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:55:08 UTC

[lucene-solr] branch branch_7_7 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_7_7
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


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

commit 621d61e7be9a2a5e3306ba823146b895229b2fbb
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                                 | 10 ++++--
 .../org/apache/lucene/store/FilterDirectory.java   |  4 ++-
 .../org/apache/lucene/index/TestIndexWriter.java   | 39 ++++++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 60faca2..d1b9252 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -3,11 +3,15 @@ Lucene Change Log
 For more information on past and future Lucene versions, please see:
 http://s.apache.org/luceneversions
 
-======================= Lucene 7.7.2 =======================
-(No Changes)
 
 ======================= Lucene 7.7.1 =======================
-(No Changes)
+
+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)
 
 ======================= Lucene 7.7.0 =======================
 
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 b877824..7e8b7ac 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -3714,4 +3714,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();
+    }
+  }
+
 }