From 044aabfb30b3da02378c33392a86adc7942921a8 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Mon, 11 Jul 2016 05:32:56 -0400 Subject: [PATCH] Remove IW.slowFileExists, since it's only called from "used to be helpful but now useless" asserts: - Directory.copyFrom now throws an exception if the test already exists - Directory.sync now throws an exception if a file name didn't already exist --- .../org/apache/lucene/index/IndexWriter.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 91b67e8d73c..0fb23d96b36 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -17,9 +17,7 @@ package org.apache.lucene.index; 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; @@ -2885,9 +2883,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { // Copy the segment's files for (String file: info.files()) { final String newFileName = newInfo.namedForThisSegment(file); - - assert !slowFileExists(directory, newFileName): "file \"" + newFileName + "\" already exists; newInfo.files=" + newInfo.files(); - directory.copyFrom(info.info.dir, file, newFileName, context); copiedFiles.add(newFileName); } @@ -4542,7 +4537,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { Collection files = toSync.files(false); for(final String fileName: files) { - 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 @@ -4999,19 +4993,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { 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. */ - static boolean slowFileExists(Directory dir, String fileName) throws IOException { - try { - dir.openInput(fileName, IOContext.DEFAULT).close(); - return true; - } catch (NoSuchFileException | FileNotFoundException e) { - return false; - } - } - /** Anything that will add N docs to the index should reserve first to * make sure it's allowed. This will throw {@code * IllegalArgumentException} if it's not allowed. */