diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index f90f9e3f8fd..1baeb7fa68e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -129,6 +129,10 @@ Bug Fixes * LUCENE-8236: Filter duplicated points when creating GeoPath shapes to avoid creation of bogus planes. (Ignacio Vera) +* LUCENE-8243: IndexWriter.addIndexes(Directory[]) did not properly preserve + index file names for updated doc values fields (Simon Willnauer, + Michael McCandless) + Other * LUCENE-8228: removed obsolete IndexDeletionPolicy clone() requirements from 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 43051769cd6..8ba460d70b5 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -3207,8 +3207,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { info.info.getDiagnostics(), info.info.getId(), info.info.getAttributes(), info.info.getIndexSort()); SegmentCommitInfo newInfoPerCommit = new SegmentCommitInfo(newInfo, info.getDelCount(), info.getDelGen(), info.getFieldInfosGen(), info.getDocValuesGen()); - - newInfo.setFiles(info.files()); + + newInfo.setFiles(info.info.files()); + newInfoPerCommit.setFieldInfosFiles(info.getFieldInfosFiles()); + newInfoPerCommit.setDocValuesUpdatesFiles(info.getDocValuesUpdatesFiles()); boolean success = false; @@ -3228,7 +3230,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { } } - assert copiedFiles.equals(newInfoPerCommit.files()); + assert copiedFiles.equals(newInfoPerCommit.files()): "copiedFiles=" + copiedFiles + " vs " + newInfoPerCommit.files(); return newInfoPerCommit; } @@ -3569,6 +3571,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { return seqNo; } + @SuppressWarnings("try") private final void finishCommit() throws IOException { boolean commitCompleted = false; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java index 876328a4a42..48a28e2e791 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -1332,4 +1332,85 @@ public class TestAddIndexes extends LuceneTestCase { assertEquals("cannot change index sort from to ", message); IOUtils.close(r1, dir1, w2, dir2); } + + public void testAddIndexesDVUpdateSameSegmentName() throws Exception { + Directory dir1 = newDirectory(); + IndexWriterConfig iwc1 = newIndexWriterConfig(new MockAnalyzer(random())); + IndexWriter w1 = new IndexWriter(dir1, iwc1); + Document doc = new Document(); + doc.add(new StringField("id", "1", Field.Store.YES)); + doc.add(new StringField("version", "1", Field.Store.YES)); + doc.add(new NumericDocValuesField("soft_delete", 1)); + w1.addDocument(doc); + w1.flush(); + + w1.updateDocValues(new Term("id", "1"), new NumericDocValuesField("soft_delete", 1)); + w1.commit(); + w1.close(); + + IndexWriterConfig iwc2 = newIndexWriterConfig(new MockAnalyzer(random())); + Directory dir2 = newDirectory(); + IndexWriter w2 = new IndexWriter(dir2, iwc2); + w2.addIndexes(dir1); + w2.commit(); + w2.close(); + + if (VERBOSE) { + System.out.println("\nTEST: now open w3"); + } + IndexWriterConfig iwc3 = newIndexWriterConfig(new MockAnalyzer(random())); + if (VERBOSE) { + iwc3.setInfoStream(System.out); + } + IndexWriter w3 = new IndexWriter(dir2, iwc3); + w3.close(); + + iwc3 = newIndexWriterConfig(new MockAnalyzer(random())); + w3 = new IndexWriter(dir2, iwc3); + w3.close(); + dir1.close(); + dir2.close(); + } + + public void testAddIndexesDVUpdateNewSegmentName() throws Exception { + Directory dir1 = newDirectory(); + IndexWriterConfig iwc1 = newIndexWriterConfig(new MockAnalyzer(random())); + IndexWriter w1 = new IndexWriter(dir1, iwc1); + Document doc = new Document(); + doc.add(new StringField("id", "1", Field.Store.YES)); + doc.add(new StringField("version", "1", Field.Store.YES)); + doc.add(new NumericDocValuesField("soft_delete", 1)); + w1.addDocument(doc); + w1.flush(); + + w1.updateDocValues(new Term("id", "1"), new NumericDocValuesField("soft_delete", 1)); + w1.commit(); + w1.close(); + + IndexWriterConfig iwc2 = newIndexWriterConfig(new MockAnalyzer(random())); + Directory dir2 = newDirectory(); + IndexWriter w2 = new IndexWriter(dir2, iwc2); + w2.addDocument(new Document()); + w2.commit(); + + w2.addIndexes(dir1); + w2.commit(); + w2.close(); + + if (VERBOSE) { + System.out.println("\nTEST: now open w3"); + } + IndexWriterConfig iwc3 = newIndexWriterConfig(new MockAnalyzer(random())); + if (VERBOSE) { + iwc3.setInfoStream(System.out); + } + IndexWriter w3 = new IndexWriter(dir2, iwc3); + w3.close(); + + iwc3 = newIndexWriterConfig(new MockAnalyzer(random())); + w3 = new IndexWriter(dir2, iwc3); + w3.close(); + dir1.close(); + dir2.close(); + } }