From 2cee9f16934b6458ee18a60d194e586c33ed36d9 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Mon, 8 Feb 2016 13:54:05 -0500 Subject: [PATCH] LUCENE-6835, LUCENE-6684: keep the 'suppress NSFE on windows' hack inside IFD as well --- .../apache/lucene/index/IndexFileDeleter.java | 19 +++++++++++++++++-- .../lucene/store/BaseLockFactoryTestCase.java | 9 ++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java index 52f0b401aff..38d16881107 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java @@ -705,14 +705,29 @@ final class IndexFileDeleter implements Closeable { if (name.startsWith(IndexFileNames.SEGMENTS) == false) { continue; } - directory.deleteFile(name); + deleteFile(name); } for(String name : names) { if (name.startsWith(IndexFileNames.SEGMENTS) == true) { continue; } - directory.deleteFile(name); + deleteFile(name); + } + } + + private void deleteFile(String fileName) throws IOException { + try { + directory.deleteFile(fileName); + } catch (NoSuchFileException | FileNotFoundException e) { + if (Constants.WINDOWS) { + // TODO: can we remove this OS-specific hacky logic? If windows deleteFile is buggy, we should instead contain this workaround in + // a WindowsFSDirectory ... + // LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, where we already + // deleted it once, yet it still shows up in directory listings, and if you try to delete it again you'll hit NSFE/FNFE: + } else { + throw e; + } } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java index f2c72685552..b2ad1781654 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java @@ -233,19 +233,14 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase { iwc.setOpenMode(OpenMode.APPEND); try { writer = new IndexWriter(dir, iwc); - } catch (LockObtainFailedException e) { - // lock obtain timed out - // NOTE: we should at some point - // consider this a failure? The lock - // obtains, across IndexReader & - // IndexWriters should be "fair" (ie - // FIFO). } catch (Throwable t) { if (Constants.WINDOWS && t instanceof AccessDeniedException) { // LUCENE-6684: suppress this: on Windows, a file in the curious "pending delete" state can // cause this exc on IW init, where one thread/process deleted an old // segments_N, but the delete hasn't finished yet because other threads/processes // still have it open + printStream.println("TEST: AccessDeniedException on init witer"); + t.printStackTrace(printStream); } else { hitException = true; System.out.println("Stress Test Index Writer: creation hit unexpected exception: " + t.toString());