blob: a5189f55e8915451c351881659237eecfac92bb1 [file] [log] [blame]
Index: lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java
===================================================================
--- lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java (revision 1579722)
+++ lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyRevisionTest.java (working copy)
@@ -82,8 +82,8 @@
Revision rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
// releasing that revision should not delete the files
rev1.release();
- assertTrue(indexDir.fileExists(IndexFileNames.SEGMENTS + "_1"));
- assertTrue(taxoDir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertTrue(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
+ assertTrue(slowFileExists(taxoDir, IndexFileNames.SEGMENTS + "_1"));
rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter); // create revision again, so the files are snapshotted
indexWriter.addDocument(newDocument(taxoWriter));
@@ -91,7 +91,7 @@
taxoWriter.commit();
assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
rev1.release(); // this release should trigger the delete of segments_1
- assertFalse(indexDir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertFalse(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
} finally {
IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
}
Index: lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java
===================================================================
--- lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java (revision 1579722)
+++ lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java (working copy)
@@ -187,11 +187,11 @@
@Test
public void testRevisionRelease() throws Exception {
replicator.publish(createRevision(1));
- assertTrue(sourceDir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertTrue(slowFileExists(sourceDir, IndexFileNames.SEGMENTS + "_1"));
replicator.publish(createRevision(2));
// now the files of revision 1 can be deleted
- assertTrue(sourceDir.fileExists(IndexFileNames.SEGMENTS + "_2"));
- assertFalse("segments_1 should not be found in index directory after revision is released", sourceDir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertTrue(slowFileExists(sourceDir, IndexFileNames.SEGMENTS + "_2"));
+ assertFalse("segments_1 should not be found in index directory after revision is released", slowFileExists(sourceDir, IndexFileNames.SEGMENTS + "_1"));
}
}
Index: lucene/replicator/src/test/org/apache/lucene/replicator/IndexRevisionTest.java
===================================================================
--- lucene/replicator/src/test/org/apache/lucene/replicator/IndexRevisionTest.java (revision 1579722)
+++ lucene/replicator/src/test/org/apache/lucene/replicator/IndexRevisionTest.java (working copy)
@@ -79,14 +79,14 @@
Revision rev1 = new IndexRevision(writer);
// releasing that revision should not delete the files
rev1.release();
- assertTrue(dir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertTrue(slowFileExists(dir, IndexFileNames.SEGMENTS + "_1"));
rev1 = new IndexRevision(writer); // create revision again, so the files are snapshotted
writer.addDocument(new Document());
writer.commit();
assertNotNull(new IndexRevision(writer));
rev1.release(); // this release should trigger the delete of segments_1
- assertFalse(dir.fileExists(IndexFileNames.SEGMENTS + "_1"));
+ assertFalse(slowFileExists(dir, IndexFileNames.SEGMENTS + "_1"));
} finally {
IOUtils.close(writer, dir);
}
Index: lucene/replicator/src/java/org/apache/lucene/replicator/IndexReplicationHandler.java
===================================================================
--- lucene/replicator/src/java/org/apache/lucene/replicator/IndexReplicationHandler.java (revision 1579722)
+++ lucene/replicator/src/java/org/apache/lucene/replicator/IndexReplicationHandler.java (working copy)
@@ -123,9 +123,7 @@
public static void cleanupFilesOnFailure(Directory dir, List<String> files) {
for (String file : files) {
try {
- if (dir.fileExists(file)) {
- dir.deleteFile(file);
- }
+ dir.deleteFile(file);
} catch (Throwable t) {
// suppress any exception because if we're here, it means copy
// failed, and we must cleanup after ourselves.
@@ -194,9 +192,7 @@
SegmentInfos.writeSegmentsGen(dir, SegmentInfos.generationFromSegmentsFileName(segmentsFile));
} else {
try {
- if (dir.fileExists(IndexFileNames.SEGMENTS_GEN)) {
- dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
- }
+ dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
} catch (Throwable t) {
// suppress any errors while deleting this file.
}
Index: lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java (working copy)
@@ -500,7 +500,7 @@
for (String name : ic.getFileNames()) {
//distribute, and backup
//System.out.println(names);
- assertTrue(dir.fileExists(name));
+ assertTrue(slowFileExists(dir, name));
}
} catch (Exception e) {
throw new RuntimeException(e);
Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (working copy)
@@ -1133,6 +1133,9 @@
}
if (!failed) {
+ if (VERBOSE) {
+ System.out.println("TEST: now rollback");
+ }
// clear interrupt state:
Thread.interrupted();
if (w != null) {
@@ -1161,10 +1164,15 @@
}
}
try {
- IOUtils.close(dir, adder);
+ IOUtils.close(dir);
} catch (IOException e) {
throw new RuntimeException(e);
}
+ try {
+ IOUtils.close(adder);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
}
@@ -1931,7 +1939,7 @@
new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))).close();
- assertTrue(dir.fileExists("myrandomfile"));
+ assertTrue(slowFileExists(dir, "myrandomfile"));
} finally {
dir.close();
}
@@ -2009,14 +2017,14 @@
new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))).close();
- assertTrue(dir.fileExists("_a.frq"));
+ assertTrue(slowFileExists(dir, "_a.frq"));
IndexWriter iw = new IndexWriter(dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
iw.addDocument(new Document());
iw.close();
- assertFalse(dir.fileExists("_a.frq"));
+ assertFalse(slowFileExists(dir, "_a.frq"));
} finally {
dir.close();
}
Index: lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java (working copy)
@@ -682,12 +682,6 @@
createSequenceFile(newDir, "d1", (byte) 0, 15);
IndexOutput out = csw.createOutput("d.xyz", newIOContext(random()));
out.writeInt(0);
- try {
- newDir.copy(csw, "d1", "d1", newIOContext(random()));
- fail("file does already exist");
- } catch (IllegalArgumentException e) {
- //
- }
out.close();
assertEquals(1, csw.listAll().length);
assertEquals("d.xyz", csw.listAll()[0]);
Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (working copy)
@@ -45,7 +45,6 @@
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
-import org.apache.lucene.util.TestUtil;
public class TestIndexWriterDelete extends LuceneTestCase {
@@ -727,7 +726,8 @@
boolean seen = false;
StackTraceElement[] trace = new Exception().getStackTrace();
for (int i = 0; i < trace.length; i++) {
- if ("applyDeletesAndUpdates".equals(trace[i].getMethodName())) {
+ if ("applyDeletesAndUpdates".equals(trace[i].getMethodName()) ||
+ "slowFileExists".equals(trace[i].getMethodName())) {
seen = true;
break;
}
@@ -1042,7 +1042,7 @@
w.updateDocument(delTerm, doc);
// Eventually segment 0 should get a del docs:
// TODO: fix this test
- if (dir.fileExists("_0_1.del") || dir.fileExists("_0_1.liv") ) {
+ if (slowFileExists(dir, "_0_1.del") || slowFileExists(dir, "_0_1.liv") ) {
if (VERBOSE) {
System.out.println("TEST: deletes created @ count=" + count);
}
@@ -1088,7 +1088,7 @@
w.updateDocument(delTerm, doc);
// Eventually segment 0 should get a del docs:
// TODO: fix this test
- if (dir.fileExists("_0_1.del") || dir.fileExists("_0_1.liv")) {
+ if (slowFileExists(dir, "_0_1.del") || slowFileExists(dir, "_0_1.liv")) {
break;
}
count++;
@@ -1135,7 +1135,7 @@
w.updateDocument(new Term("id", ""+id), doc);
docsInSegment.incrementAndGet();
// TODO: fix this test
- if (dir.fileExists("_0_1.del") || dir.fileExists("_0_1.liv")) {
+ if (slowFileExists(dir, "_0_1.del") || slowFileExists(dir, "_0_1.liv")) {
if (VERBOSE) {
System.out.println("TEST: deletes created @ id=" + id);
}
Index: lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java (working copy)
@@ -121,10 +121,6 @@
return fsDir.listAll();
}
@Override
- public boolean fileExists(String name) throws IOException {
- return fsDir.fileExists(name);
- }
- @Override
public void deleteFile(String name) throws IOException {
fsDir.deleteFile(name);
}
Index: lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java (working copy)
@@ -51,7 +51,7 @@
protected void checkSnapshotExists(Directory dir, IndexCommit c) throws Exception {
String segFileName = c.getSegmentsFileName();
- assertTrue("segments file not found in directory: " + segFileName, dir.fileExists(segFileName));
+ assertTrue("segments file not found in directory: " + segFileName, slowFileExists(dir, segFileName));
}
protected void checkMaxDoc(IndexCommit commit, int expectedMaxDoc) throws Exception {
@@ -338,7 +338,7 @@
// but 'snapshot1' files will still exist (need to release snapshot before they can be deleted).
String segFileName = snapshots.get(1).getSegmentsFileName();
- assertTrue("snapshot files should exist in the directory: " + segFileName, dir.fileExists(segFileName));
+ assertTrue("snapshot files should exist in the directory: " + segFileName, slowFileExists(dir, segFileName));
dir.close();
}
@@ -360,7 +360,7 @@
sdp.release(snapshots.get(0));
writer.deleteUnusedFiles();
writer.close();
- assertFalse("segments file should not be found in dirctory: " + segFileName, dir.fileExists(segFileName));
+ assertFalse("segments file should not be found in dirctory: " + segFileName, slowFileExists(dir, segFileName));
dir.close();
}
@@ -409,7 +409,7 @@
// commit.
new IndexWriter(dir, getConfig(random(), null)).close();
- assertFalse("snapshotted commit should not exist", dir.fileExists(s1.getSegmentsFileName()));
+ assertFalse("snapshotted commit should not exist", slowFileExists(dir, s1.getSegmentsFileName()));
dir.close();
}
}
Index: lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java (working copy)
@@ -91,7 +91,7 @@
allFiles.addAll(ic.getFileNames());
// Make sure no old files were removed
for(String fileName : allFiles) {
- assertTrue("file " + fileName + " does not exist", d.fileExists(fileName));
+ assertTrue("file " + fileName + " does not exist", slowFileExists(d, fileName));
}
DirectoryReader r2 = DirectoryReader.openIfChanged(r);
if (r2 != null) {
Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java (working copy)
@@ -83,6 +83,7 @@
}
w.addDocument(docs.nextDoc());
}
+ dir.setRandomIOExceptionRateOnOpen(0.0);
w.close();
w = null;
Index: lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java (working copy)
@@ -33,7 +33,6 @@
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
-import org.apache.lucene.util.TestUtil;
public class TestCrashCausesCorruptIndex extends LuceneTestCase {
@@ -83,7 +82,7 @@
}
// writes segments_3
indexWriter.close();
- assertFalse(realDirectory.fileExists("segments_2"));
+ assertFalse(slowFileExists(realDirectory, "segments_2"));
crashAfterCreateOutput.close();
}
@@ -103,7 +102,7 @@
// however, to test the fix, the following lines should pass as well.
indexWriter.addDocument(getDocument());
indexWriter.close();
- assertFalse(realDirectory.fileExists("segments_2"));
+ assertFalse(slowFileExists(realDirectory, "segments_2"));
realDirectory.close();
}
Index: lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java (working copy)
@@ -116,8 +116,8 @@
// Create a bogus cfs file shadowing a non-cfs segment:
// TODO: assert is bogus (relies upon codec-specific filenames)
- assertTrue(dir.fileExists("_3.fdt") || dir.fileExists("_3.fld"));
- assertTrue(!dir.fileExists("_3.cfs"));
+ assertTrue(slowFileExists(dir, "_3.fdt") || slowFileExists(dir, "_3.fld"));
+ assertTrue(!slowFileExists(dir, "_3.cfs"));
copyFile(dir, "_1.cfs", "_3.cfs");
String[] filesPre = dir.listAll();
Index: lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java (working copy)
@@ -122,7 +122,7 @@
String name = "file";
try {
dir.createOutput(name, newIOContext(random())).close();
- assertTrue(dir.fileExists(name));
+ assertTrue(slowFileExists(dir, name));
assertTrue(Arrays.asList(dir.listAll()).contains(name));
} finally {
dir.close();
@@ -136,12 +136,6 @@
createSequenceFile(newDir, "d1", (byte) 0, 15);
IndexOutput out = csw.createOutput("d.xyz", newIOContext(random()));
out.writeInt(0);
- try {
- newDir.copy(csw, "d1", "d1", newIOContext(random()));
- fail("file does already exist");
- } catch (IllegalArgumentException e) {
- //
- }
out.close();
assertEquals(1, csw.listAll().length);
assertEquals("d.xyz", csw.listAll()[0]);
Index: lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (working copy)
@@ -40,7 +40,6 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
-import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.ArrayUtil;
public class TestBufferedIndexInput extends LuceneTestCase {
@@ -330,12 +329,6 @@
dir.deleteFile(name);
}
@Override
- public boolean fileExists(String name)
- throws IOException
- {
- return dir.fileExists(name);
- }
- @Override
public String[] listAll()
throws IOException
{
Index: lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (working copy)
@@ -74,7 +74,7 @@
//System.out.println("create:" + fileName);
IndexOutput output = dir.createOutput(fileName, newIOContext(random()));
output.close();
- assertTrue(dir.fileExists(fileName));
+ assertTrue(slowFileExists(dir, fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -160,7 +160,7 @@
for (int j=0; j<dirs.length; j++) {
FSDirectory d2 = dirs[j];
d2.ensureOpen();
- assertTrue(d2.fileExists(fname));
+ assertTrue(slowFileExists(d2, fname));
assertEquals(1 + largeBuffer.length, d2.fileLength(fname));
// don't do read tests if unmapping is not supported!
@@ -186,7 +186,7 @@
for (int j=0; j<dirs.length; j++) {
FSDirectory d2 = dirs[j];
- assertFalse(d2.fileExists(fname));
+ assertFalse(slowFileExists(d2, fname));
}
Lock lock = dir.makeLock(lockname);
@@ -248,7 +248,7 @@
String name = "file";
try {
dir.createOutput(name, newIOContext(random())).close();
- assertTrue(dir.fileExists(name));
+ assertTrue(slowFileExists(dir, name));
assertTrue(Arrays.asList(dir.listAll()).contains(name));
} finally {
dir.close();
@@ -275,7 +275,7 @@
try {
IndexOutput out = fsDir.createOutput("afile", newIOContext(random()));
out.close();
- assertTrue(fsDir.fileExists("afile"));
+ assertTrue(slowFileExists(fsDir, "afile"));
try {
new SimpleFSDirectory(new File(path, "afile"), null);
fail("did not hit expected exception");
Index: lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (revision 1579722)
+++ lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (working copy)
@@ -141,7 +141,7 @@
String name = "file";
try {
dir.createOutput(name, newIOContext(random())).close();
- assertTrue(dir.fileExists(name));
+ assertTrue(slowFileExists(dir, name));
assertTrue(Arrays.asList(dir.listAll()).contains(name));
} finally {
dir.close();
@@ -155,12 +155,6 @@
createSequenceFile(newDir, "d1", (byte) 0, 15);
IndexOutput out = csw.createOutput("d.xyz", newIOContext(random()));
out.writeInt(0);
- try {
- newDir.copy(csw, "d1", "d1", newIOContext(random()));
- fail("file does already exist");
- } catch (IllegalArgumentException e) {
- //
- }
out.close();
assertEquals(1, csw.listAll().length);
assertEquals("d.xyz", csw.listAll()[0]);
Index: lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/FSDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/FSDirectory.java (working copy)
@@ -234,14 +234,6 @@
return listAll(directory);
}
- /** Returns true iff a file with the given name exists. */
- @Override
- public boolean fileExists(String name) {
- ensureOpen();
- File file = new File(directory, name);
- return file.exists();
- }
-
/** Returns the length in bytes of a file in the directory. */
@Override
public long fileLength(String name) throws IOException {
Index: lucene/core/src/java/org/apache/lucene/store/Directory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/Directory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/Directory.java (working copy)
@@ -53,10 +53,6 @@
*/
public abstract String[] listAll() throws IOException;
- /** Returns true iff a file with the given name exists. */
- public abstract boolean fileExists(String name)
- throws IOException;
-
/** Removes an existing file in the directory. */
public abstract void deleteFile(String name)
throws IOException;
Index: lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java (working copy)
@@ -49,11 +49,6 @@
}
@Override
- public boolean fileExists(String name) throws IOException {
- return in.fileExists(name);
- }
-
- @Override
public void deleteFile(String name) throws IOException {
in.deleteFile(name);
}
Index: lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java (working copy)
@@ -118,9 +118,7 @@
return names.toArray(new String[names.size()]);
}
- /** Returns true iff the named file exists in this directory. */
- @Override
- public final boolean fileExists(String name) {
+ public final boolean fileNameExists(String name) {
ensureOpen();
return fileMap.containsKey(name);
}
Index: lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java (working copy)
@@ -204,16 +204,6 @@
return res;
}
- /** Returns true iff a file with the given name exists. */
- @Override
- public boolean fileExists(String name) {
- ensureOpen();
- if (this.writer != null) {
- return writer.fileExists(name);
- }
- return entries.containsKey(IndexFileNames.stripSegmentName(name));
- }
-
/** Not implemented
* @throws UnsupportedOperationException always: not supported by CFS */
@Override
Index: lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java (working copy)
@@ -152,17 +152,11 @@
}
@Override
- public synchronized boolean fileExists(String name) throws IOException {
- return cache.fileExists(name) || delegate.fileExists(name);
- }
-
- @Override
public synchronized void deleteFile(String name) throws IOException {
if (VERBOSE) {
System.out.println("nrtdir.deleteFile name=" + name);
}
- if (cache.fileExists(name)) {
- assert !delegate.fileExists(name): "name=" + name;
+ if (cache.fileNameExists(name)) {
cache.deleteFile(name);
} else {
delegate.deleteFile(name);
@@ -171,7 +165,7 @@
@Override
public synchronized long fileLength(String name) throws IOException {
- if (cache.fileExists(name)) {
+ if (cache.fileNameExists(name)) {
return cache.fileLength(name);
} else {
return delegate.fileLength(name);
@@ -223,7 +217,7 @@
if (VERBOSE) {
System.out.println("nrtdir.openInput name=" + name);
}
- if (cache.fileExists(name)) {
+ if (cache.fileNameExists(name)) {
if (VERBOSE) {
System.out.println(" from cache");
}
@@ -239,7 +233,7 @@
if (VERBOSE) {
System.out.println("nrtdir.openInput name=" + name);
}
- if (cache.fileExists(name)) {
+ if (cache.fileNameExists(name)) {
if (VERBOSE) {
System.out.println(" from cache");
}
@@ -289,13 +283,10 @@
if (VERBOSE) {
System.out.println("nrtdir.unCache name=" + fileName);
}
- if (!cache.fileExists(fileName)) {
+ if (!cache.fileNameExists(fileName)) {
// Another thread beat us...
return;
}
- if (delegate.fileExists(fileName)) {
- throw new IOException("cannot uncache file=\"" + fileName + "\": it was separately also created in the delegate directory");
- }
final IOContext context = IOContext.DEFAULT;
final IndexOutput out = delegate.createOutput(fileName, context);
IndexInput in = null;
@@ -309,7 +300,7 @@
// Lock order: uncacheLock -> this
synchronized(this) {
// Must sync here because other sync methods have
- // if (cache.fileExists(name)) { ... } else { ... }:
+ // if (cache.fileNameExists(name)) { ... } else { ... }:
cache.deleteFile(fileName);
}
}
Index: lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java (working copy)
@@ -225,9 +225,6 @@
out = new DirectCFSIndexOutput(getOutput(), entry, false);
} else {
entry.dir = this.directory;
- if (directory.fileExists(name)) {
- throw new IllegalArgumentException("File " + name + " already exists");
- }
out = new DirectCFSIndexOutput(directory.createOutput(name, context), entry,
true);
}
Index: lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java (working copy)
@@ -133,11 +133,6 @@
}
@Override
- public boolean fileExists(String name) throws IOException {
- return getDirectory(name).fileExists(name);
- }
-
- @Override
public void deleteFile(String name) throws IOException {
getDirectory(name).deleteFile(name);
}
Index: lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (working copy)
@@ -584,23 +584,20 @@
}
directory.deleteFile(fileName);
} catch (IOException e) { // if delete fails
- if (directory.fileExists(fileName)) {
+ // Some operating systems (e.g. Windows) don't
+ // permit a file to be deleted while it is opened
+ // for read (e.g. by another process or thread). So
+ // we assume that when a delete fails it is because
+ // the file is open in another process, and queue
+ // the file for subsequent deletion.
- // Some operating systems (e.g. Windows) don't
- // permit a file to be deleted while it is opened
- // for read (e.g. by another process or thread). So
- // we assume that when a delete fails it is because
- // the file is open in another process, and queue
- // the file for subsequent deletion.
-
- if (infoStream.isEnabled("IFD")) {
- infoStream.message("IFD", "unable to remove file \"" + fileName + "\": " + e.toString() + "; Will re-try later.");
- }
- if (deletable == null) {
- deletable = new ArrayList<>();
- }
- deletable.add(fileName); // add to deletable
+ if (infoStream.isEnabled("IFD")) {
+ infoStream.message("IFD", "unable to remove file \"" + fileName + "\": " + e.toString() + "; Will re-try later.");
}
+ if (deletable == null) {
+ deletable = new ArrayList<>();
+ }
+ deletable.add(fileName); // add to deletable
}
}
Index: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (working copy)
@@ -18,8 +18,11 @@
*/
import java.io.Closeable;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -29,8 +32,8 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
+import java.util.Map.Entry;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -2758,7 +2761,7 @@
continue;
}
- assert !directory.fileExists(newFileName): "file \"" + newFileName + "\" already exists; siFiles=" + siFiles;
+ assert !slowFileExists(directory, newFileName): "file \"" + newFileName + "\" already exists; siFiles=" + siFiles;
info.info.dir.copy(directory, file, newFileName, context);
}
@@ -2897,17 +2900,18 @@
if (anySegmentsFlushed) {
maybeMerge(MergeTrigger.FULL_FLUSH, UNBOUNDED_MAX_MERGE_SEGMENTS);
}
+ startCommit(toCommit);
success = true;
} finally {
if (!success) {
synchronized (this) {
- deleter.decRef(filesToCommit);
- filesToCommit = null;
+ if (filesToCommit != null) {
+ deleter.decRef(filesToCommit);
+ filesToCommit = null;
+ }
}
}
}
-
- startCommit(toCommit);
}
}
@@ -4282,7 +4286,7 @@
Collection<String> files = toSync.files(directory, false);
for(final String fileName: files) {
- assert directory.fileExists(fileName): "file " + fileName + " does not exist";
+ assert slowFileExists(directory, fileName): "file " + fileName + " does not exist; files=" + Arrays.toString(directory.listAll());
// If this trips it means we are missing a call to
// .checkpoint somewhere, because by the time we
// are called, deleter should know about every
@@ -4683,4 +4687,16 @@
void process(IndexWriter writer, boolean triggerMerge, boolean clearBuffers) throws IOException;
}
+ /** Used only by asserts: returns true if the file exists
+ * (can be opened), false if it cannot be opened, and
+ * (unlike Java's File.exists) throws IOException if
+ * there's some unexpected error. */
+ private static boolean slowFileExists(Directory dir, String fileName) throws IOException {
+ try {
+ dir.openInput(fileName, IOContext.DEFAULT).close();
+ return true;
+ } catch (NoSuchFileException | FileNotFoundException e) {
+ return false;
+ }
+ }
}
Index: lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (working copy)
@@ -752,9 +752,15 @@
"",
gen-1);
- final boolean prevExists;
- prevExists = directory.fileExists(prevSegmentFileName);
+ boolean prevExists;
+ try {
+ directory.openInput(prevSegmentFileName, IOContext.DEFAULT).close();
+ prevExists = true;
+ } catch (IOException ioe) {
+ prevExists = false;
+ }
+
if (prevExists) {
if (infoStream != null) {
message("fallback to prior segment file '" + prevSegmentFileName + "'");
Index: lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java (revision 1579722)
+++ lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java (working copy)
@@ -206,8 +206,10 @@
if (nextWriteGen > 0) {
String lastSaveFile = SNAPSHOTS_PREFIX + (nextWriteGen-1);
- if (dir.fileExists(lastSaveFile)) {
+ try {
dir.deleteFile(lastSaveFile);
+ } catch (IOException ioe) {
+ // OK: likely it didn't exist
}
}
Index: lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
===================================================================
--- lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (revision 1579722)
+++ lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (working copy)
@@ -18,6 +18,7 @@
*/
import java.io.*;
+import java.nio.file.NoSuchFileException;
import java.lang.annotation.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -2063,4 +2064,17 @@
assertEquals(info, left, right);
}
+
+ /** Returns true if the file exists (can be opened), false
+ * if it cannot be opened, and (unlike Java's
+ * File.exists) throws IOException if there's some
+ * unexpected error. */
+ public static boolean slowFileExists(Directory dir, String fileName) throws IOException {
+ try {
+ dir.openInput(fileName, IOContext.DEFAULT).close();
+ return true;
+ } catch (NoSuchFileException | FileNotFoundException e) {
+ return false;
+ }
+ }
}
Index: lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
===================================================================
--- lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (revision 1579722)
+++ lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (working copy)
@@ -251,7 +251,7 @@
String tempFileName;
while (true) {
tempFileName = ""+randomState.nextInt();
- if (!in.fileExists(tempFileName)) {
+ if (!LuceneTestCase.slowFileExists(in, tempFileName)) {
break;
}
}
@@ -549,7 +549,7 @@
if (failOnOpenInput) {
maybeThrowDeterministicException();
}
- if (!in.fileExists(name)) {
+ if (!LuceneTestCase.slowFileExists(in, name)) {
throw randomState.nextBoolean() ? new FileNotFoundException(name + " in dir=" + in) : new NoSuchFileException(name + " in dir=" + in);
}
@@ -865,12 +865,6 @@
}
@Override
- public synchronized boolean fileExists(String name) throws IOException {
- maybeYield();
- return in.fileExists(name);
- }
-
- @Override
public synchronized long fileLength(String name) throws IOException {
maybeYield();
return in.fileLength(name);
@@ -925,7 +919,7 @@
public IndexInputSlicer createSlicer(final String name, IOContext context)
throws IOException {
maybeYield();
- if (!in.fileExists(name)) {
+ if (!LuceneTestCase.slowFileExists(in, name)) {
throw randomState.nextBoolean() ? new FileNotFoundException(name) : new NoSuchFileException(name);
}
// cannot open a file for input if it's still open for
Index: solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
===================================================================
--- solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java (revision 1579722)
+++ solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java (working copy)
@@ -118,10 +118,10 @@
assertEquals(12345, input1.readInt());
input1.close();
- assertFalse(directory.fileExists("testing.test.other"));
- assertTrue(directory.fileExists("testing.test"));
+ assertFalse(slowFileExists(directory, "testing.test.other"));
+ assertTrue(slowFileExists(directory, "testing.test"));
directory.deleteFile("testing.test");
- assertFalse(directory.fileExists("testing.test"));
+ assertFalse(slowFileExists(directory, "testing.test"));
}
@Test
Index: solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java
===================================================================
--- solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java (working copy)
@@ -369,10 +369,6 @@
directory.deleteFile(name);
}
- public boolean fileExists(String name) throws IOException {
- return directory.fileExists(name);
- }
-
public long fileLength(String name) throws IOException {
return directory.fileLength(name);
}
Index: solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java
===================================================================
--- solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java (working copy)
@@ -144,11 +144,6 @@
}
@Override
- public boolean fileExists(String name) throws IOException {
- return getFileSystem().exists(new Path(hdfsDirPath, name));
- }
-
- @Override
public long fileLength(String name) throws IOException {
return HdfsFileReader.getLength(getFileSystem(),
new Path(hdfsDirPath, name));
Index: solr/core/src/java/org/apache/solr/core/SolrCore.java
===================================================================
--- solr/core/src/java/org/apache/solr/core/SolrCore.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/core/SolrCore.java (working copy)
@@ -18,14 +18,16 @@
package org.apache.solr.core;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.net.URL;
+import java.nio.file.NoSuchFileException;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -49,7 +51,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
-
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
@@ -66,8 +67,8 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.params.CommonParams.EchoParamStyle;
import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.CommonParams.EchoParamStyle;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
@@ -77,6 +78,7 @@
import org.apache.solr.handler.admin.ShowFileRequestHandler;
import org.apache.solr.handler.component.AnalyticsComponent;
import org.apache.solr.handler.component.DebugComponent;
+import org.apache.solr.handler.component.ExpandComponent;
import org.apache.solr.handler.component.FacetComponent;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.handler.component.MoreLikeThisComponent;
@@ -84,7 +86,6 @@
import org.apache.solr.handler.component.RealTimeGetComponent;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.StatsComponent;
-import org.apache.solr.handler.component.ExpandComponent;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.BinaryResponseWriter;
@@ -100,9 +101,9 @@
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.response.XMLResponseWriter;
import org.apache.solr.response.transform.TransformerFactory;
+import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
import org.apache.solr.rest.ManagedResourceStorage;
import org.apache.solr.rest.RestManager;
-import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.IndexSchemaFactory;
@@ -113,8 +114,8 @@
import org.apache.solr.search.ValueSourceParser;
import org.apache.solr.update.DefaultSolrCoreState;
import org.apache.solr.update.DirectUpdateHandler2;
+import org.apache.solr.update.SolrCoreState.IndexWriterCloser;
import org.apache.solr.update.SolrCoreState;
-import org.apache.solr.update.SolrCoreState.IndexWriterCloser;
import org.apache.solr.update.SolrIndexWriter;
import org.apache.solr.update.UpdateHandler;
import org.apache.solr.update.VersionInfo;
@@ -263,9 +264,14 @@
Directory dir = null;
try {
dir = getDirectoryFactory().get(getDataDir(), DirContext.META_DATA, getSolrConfig().indexConfig.lockType);
- if (dir.fileExists(SnapPuller.INDEX_PROPERTIES)){
- final IndexInput input = dir.openInput(SnapPuller.INDEX_PROPERTIES, IOContext.DEFAULT);
-
+ IndexInput input;
+ try {
+ input = dir.openInput(SnapPuller.INDEX_PROPERTIES, IOContext.DEFAULT);
+ } catch (FileNotFoundException | NoSuchFileException e) {
+ input = null;
+ }
+
+ if (input != null) {
final InputStream is = new PropertiesInputStream(input);
try {
p.load(new InputStreamReader(is, "UTF-8"));
Index: solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
===================================================================
--- solr/core/src/java/org/apache/solr/core/DirectoryFactory.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/core/DirectoryFactory.java (working copy)
@@ -19,7 +19,9 @@
import java.io.Closeable;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.NoSuchFileException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FlushInfo;
@@ -202,11 +204,11 @@
}
public static long sizeOf(Directory directory, String file) throws IOException {
- if (!directory.fileExists(file)) {
+ try {
+ return directory.fileLength(file);
+ } catch (FileNotFoundException | NoSuchFileException e) {
return 0;
}
-
- return directory.fileLength(file);
}
/**
Index: solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
===================================================================
--- solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java (working copy)
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -25,6 +26,7 @@
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -43,19 +45,16 @@
import java.util.zip.DeflaterOutputStream;
import org.apache.commons.io.IOUtils;
+import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexDeletionPolicy;
-import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
-
-import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
-
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
@@ -64,12 +63,12 @@
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CloseHook;
+import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.DirectoryFactory;
import org.apache.solr.core.IndexDeletionPolicyWrapper;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrDeletionPolicy;
import org.apache.solr.core.SolrEventListener;
-import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.BinaryQueryResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
@@ -82,6 +81,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
+
/**
* <p> A Handler which provides a REST API for replication and serves replication requests from Slaves. <p/> </p>
* <p>When running on the master, it provides the following commands <ol> <li>Get the current replicable index version
@@ -811,11 +812,14 @@
try {
dir = core.getDirectoryFactory().get(core.getDataDir(),
DirContext.META_DATA, core.getSolrConfig().indexConfig.lockType);
- if (!dir.fileExists(SnapPuller.REPLICATION_PROPERTIES)) {
+ IndexInput input;
+ try {
+ input = dir.openInput(
+ SnapPuller.REPLICATION_PROPERTIES, IOContext.DEFAULT);
+ } catch (FileNotFoundException | NoSuchFileException e) {
return new Properties();
}
- final IndexInput input = dir.openInput(
- SnapPuller.REPLICATION_PROPERTIES, IOContext.DEFAULT);
+
try {
final InputStream is = new PropertiesInputStream(input);
Properties props = new Properties();
Index: solr/core/src/java/org/apache/solr/handler/SnapPuller.java
===================================================================
--- solr/core/src/java/org/apache/solr/handler/SnapPuller.java (revision 1579722)
+++ solr/core/src/java/org/apache/solr/handler/SnapPuller.java (working copy)
@@ -16,28 +16,8 @@
*/
package org.apache.solr.handler;
-import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
-import static org.apache.solr.handler.ReplicationHandler.ALIAS;
-import static org.apache.solr.handler.ReplicationHandler.CHECKSUM;
-import static org.apache.solr.handler.ReplicationHandler.CMD_DETAILS;
-import static org.apache.solr.handler.ReplicationHandler.CMD_GET_FILE;
-import static org.apache.solr.handler.ReplicationHandler.CMD_GET_FILE_LIST;
-import static org.apache.solr.handler.ReplicationHandler.CMD_INDEX_VERSION;
-import static org.apache.solr.handler.ReplicationHandler.COMMAND;
-import static org.apache.solr.handler.ReplicationHandler.COMPRESSION;
-import static org.apache.solr.handler.ReplicationHandler.CONF_FILES;
-import static org.apache.solr.handler.ReplicationHandler.CONF_FILE_SHORT;
-import static org.apache.solr.handler.ReplicationHandler.EXTERNAL;
-import static org.apache.solr.handler.ReplicationHandler.FILE;
-import static org.apache.solr.handler.ReplicationHandler.FILE_STREAM;
-import static org.apache.solr.handler.ReplicationHandler.GENERATION;
-import static org.apache.solr.handler.ReplicationHandler.INTERNAL;
-import static org.apache.solr.handler.ReplicationHandler.MASTER_URL;
-import static org.apache.solr.handler.ReplicationHandler.NAME;
-import static org.apache.solr.handler.ReplicationHandler.OFFSET;
-import static org.apache.solr.handler.ReplicationHandler.SIZE;
-
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -46,6 +26,7 @@
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.file.NoSuchFileException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -76,22 +57,23 @@
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.FastInputStream;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.DirectoryFactory;
-import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.IndexDeletionPolicyWrapper;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.ReplicationHandler.FileInfo;
@@ -108,6 +90,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
+import static org.apache.solr.handler.ReplicationHandler.ALIAS;
+import static org.apache.solr.handler.ReplicationHandler.CHECKSUM;
+import static org.apache.solr.handler.ReplicationHandler.CMD_DETAILS;
+import static org.apache.solr.handler.ReplicationHandler.CMD_GET_FILE;
+import static org.apache.solr.handler.ReplicationHandler.CMD_GET_FILE_LIST;
+import static org.apache.solr.handler.ReplicationHandler.CMD_INDEX_VERSION;
+import static org.apache.solr.handler.ReplicationHandler.COMMAND;
+import static org.apache.solr.handler.ReplicationHandler.COMPRESSION;
+import static org.apache.solr.handler.ReplicationHandler.CONF_FILES;
+import static org.apache.solr.handler.ReplicationHandler.CONF_FILE_SHORT;
+import static org.apache.solr.handler.ReplicationHandler.EXTERNAL;
+import static org.apache.solr.handler.ReplicationHandler.FILE;
+import static org.apache.solr.handler.ReplicationHandler.FILE_STREAM;
+import static org.apache.solr.handler.ReplicationHandler.GENERATION;
+import static org.apache.solr.handler.ReplicationHandler.INTERNAL;
+import static org.apache.solr.handler.ReplicationHandler.MASTER_URL;
+import static org.apache.solr.handler.ReplicationHandler.NAME;
+import static org.apache.solr.handler.ReplicationHandler.OFFSET;
+import static org.apache.solr.handler.ReplicationHandler.SIZE;
+
/**
* <p/> Provides functionality of downloading changed index files as well as config files and a timer for scheduling fetches from the
* master. </p>
@@ -763,7 +766,7 @@
LOG.debug("Download files to dir: " + Arrays.asList(indexDir.listAll()));
}
for (Map<String,Object> file : filesToDownload) {
- if (!indexDir.fileExists((String) file.get(NAME))
+ if (!slowFileExists(indexDir, (String) file.get(NAME))
|| downloadCompleteIndex) {
dirFileFetcher = new DirectoryFileFetcher(tmpIndexDir, file,
(String) file.get(NAME), false, latestGeneration);
@@ -777,6 +780,19 @@
}
}
+ /** Returns true if the file exists (can be opened), false
+ * if it cannot be opened, and (unlike Java's
+ * File.exists) throws IOException if there's some
+ * unexpected error. */
+ private static boolean slowFileExists(Directory dir, String fileName) throws IOException {
+ try {
+ dir.openInput(fileName, IOContext.DEFAULT).close();
+ return true;
+ } catch (NoSuchFileException | FileNotFoundException e) {
+ return false;
+ }
+ }
+
/**
* All the files which are common between master and slave must have same size else we assume they are
* not compatible (stale).
@@ -786,7 +802,7 @@
*/
private boolean isIndexStale(Directory dir) throws IOException {
for (Map<String, Object> file : filesToDownload) {
- if (dir.fileExists((String) file.get(NAME))
+ if (slowFileExists(dir, (String) file.get(NAME))
&& dir.fileLength((String) file.get(NAME)) != (Long) file.get(SIZE)) {
LOG.warn("File " + file.get(NAME) + " expected to be " + file.get(SIZE)
+ " while it is " + dir.fileLength((String) file.get(NAME)));
@@ -806,7 +822,7 @@
LOG.debug("Moving file: {}", fname);
boolean success = false;
try {
- if (indexDir.fileExists(fname)) {
+ if (slowFileExists(indexDir, fname)) {
LOG.info("Skipping move file - it already exists:" + fname);
return true;
}
@@ -927,7 +943,7 @@
Directory dir = null;
try {
dir = solrCore.getDirectoryFactory().get(solrCore.getDataDir(), DirContext.META_DATA, solrCore.getSolrConfig().indexConfig.lockType);
- if (dir.fileExists(SnapPuller.INDEX_PROPERTIES)){
+ if (slowFileExists(dir, SnapPuller.INDEX_PROPERTIES)){
final IndexInput input = dir.openInput(SnapPuller.INDEX_PROPERTIES, DirectoryFactory.IOCONTEXT_NO_CACHE);
final InputStream is = new PropertiesInputStream(input);