You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2019/03/26 14:43:38 UTC

[lucene-solr] branch branch_8_0 updated: LUCENE-8735: FilterDirectory.getPendingDeletions now delegates

This is an automated email from the ASF dual-hosted git repository.

simonw pushed a commit to branch branch_8_0
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8_0 by this push:
     new b7de8ce  LUCENE-8735: FilterDirectory.getPendingDeletions now delegates
b7de8ce is described below

commit b7de8cedefe538caaa464a273eda8e2070241c3d
Author: Simon Willnauer <si...@apache.org>
AuthorDate: Tue Mar 26 15:15:21 2019 +0100

    LUCENE-8735: FilterDirectory.getPendingDeletions now delegates
    
    FilterDirectory.getPendingDeletions now forwards to the delegate
    even the method is not abstract in the super class. This prevents
    issues where our best effort in carrying on generations in the
    IndexWriter since pending deletions are swallowed by the FilterDirectory.
---
 lucene/CHANGES.txt                                 |  7 ++++
 .../org/apache/lucene/store/FilterDirectory.java   |  4 ++-
 .../org/apache/lucene/index/TestIndexWriter.java   | 39 ++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e599d02..01a25e1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -5,6 +5,13 @@ http://s.apache.org/luceneversions
 
 ======================= Lucene 8.0.1 =======================
 
+Bug fixes:
+
+* LUCENE-8735: FilterDirectory.getPendingDeletions now forwards to the delegate
+  even the method is not abstract in the super class. This prevents issues
+  where our best effort in carrying on generations in the IndexWriter since pending
+  deletions are swallowed by the FilterDirectory. (Henning Andersen, Simon Willnauer)
+
 Other
 
 * LUCENE-8729: Workaround: Disable accessibility doclints (Java 13+),
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
index 7b2a6c7..f8d406e 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
@@ -117,6 +117,8 @@ public abstract class FilterDirectory extends Directory {
 
   @Override
   public Set<String> getPendingDeletions() throws IOException {
-    return super.getPendingDeletions();
+    // even the method is not abstract in the super class we delegate here since
+    // it's made abstract in 8.1 and fixes a pretty bad bug in LUCENE-8735
+    return in.getPendingDeletions();
   }
 }
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index 41fdd4b..42089a0 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -3691,4 +3691,43 @@ public class TestIndexWriter extends LuceneTestCase {
     dir.close();
   }
 
+  public void testPendingDeletionsRollbackWithReader() throws IOException {
+    // irony: currently we don't emulate windows well enough to work on windows!
+    assumeFalse("windows is not supported", Constants.WINDOWS);
+
+    Path path = createTempDir();
+
+    // Use WindowsFS to prevent open files from being deleted:
+    FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
+    Path root = new FilterPath(path, fs);
+    try (FSDirectory _dir = new SimpleFSDirectory(root)) {
+      Directory dir = new FilterDirectory(_dir) {};
+
+      IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+      IndexWriter w = new IndexWriter(dir, iwc);
+      Document d = new Document();
+      d.add(new StringField("id", "1", Field.Store.YES));
+      d.add(new NumericDocValuesField("numval", 1));
+      w.addDocument(d);
+      w.commit();
+      w.addDocument(d);
+      w.flush();
+      DirectoryReader reader = DirectoryReader.open(w);
+      w.rollback();
+
+      // try-delete superfluous files (some will fail due to windows-fs)
+      IndexWriterConfig iwc2 = new IndexWriterConfig(new MockAnalyzer(random()));
+      new IndexWriter(dir, iwc2).close();
+
+      // test that we can index on top of pending deletions
+      IndexWriterConfig iwc3 = new IndexWriterConfig(new MockAnalyzer(random()));
+      w = new IndexWriter(dir, iwc3);
+      w.addDocument(d);
+      w.commit();
+
+      reader.close();
+      w.close();
+    }
+  }
+
 }