Index: lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWCodec.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWCodec.java (revision 1378691) +++ lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWCodec.java (working copy) @@ -38,8 +38,6 @@ private final TermVectorsFormat termVectors = new PreFlexRWTermVectorsFormat(); private final SegmentInfoFormat segmentInfos = new PreFlexRWSegmentInfoFormat(); private final StoredFieldsFormat storedFields = new PreFlexRWStoredFieldsFormat(); - // TODO: this should really be a different impl - private final LiveDocsFormat liveDocs = new Lucene40LiveDocsFormat(); @Override public PostingsFormat postingsFormat() { @@ -87,15 +85,6 @@ } @Override - public LiveDocsFormat liveDocsFormat() { - if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) { - return liveDocs; - } else { - return super.liveDocsFormat(); - } - } - - @Override public StoredFieldsFormat storedFieldsFormat() { if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) { return storedFields; Index: lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (revision 1378691) +++ lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (working copy) @@ -302,6 +302,49 @@ } } + public void testDeleteOldIndex() throws IOException { + for (String name : oldNames) { + if (VERBOSE) { + System.out.println("TEST: oldName=" + name); + } + + // Try one delete: + Directory dir = newDirectory(oldIndexDirs.get(name)); + + IndexReader ir = DirectoryReader.open(dir); + assertEquals(35, ir.numDocs()); + ir.close(); + + IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)); + iw.deleteDocuments(new Term("id", "3")); + iw.close(); + + ir = DirectoryReader.open(dir); + assertEquals(34, ir.numDocs()); + ir.close(); + + // Delete all but 1 document: + iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)); + for(int i=0;i<35;i++) { + iw.deleteDocuments(new Term("id", ""+i)); + } + + // Verify NRT reader takes: + ir = DirectoryReader.open(iw, true); + iw.close(); + + assertEquals("index " + name, 1, ir.numDocs()); + ir.close(); + + // Verify non-NRT reader takes: + ir = DirectoryReader.open(dir); + assertEquals("index " + name, 1, ir.numDocs()); + ir.close(); + + dir.close(); + } + } + private void doTestHits(ScoreDoc[] hits, int expectedCount, IndexReader reader) throws IOException { final int hitCount = hits.length; assertEquals("wrong number of hits", expectedCount, hitCount); Index: lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java =================================================================== --- lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java (revision 1378691) +++ lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java (working copy) @@ -68,12 +68,7 @@ static final String COMPOUND_FILE_STORE_EXTENSION = "cfx"; // TODO: this should really be a different impl - private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat() { - @Override - public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfoPerCommit info, int newDelCount, IOContext context) throws IOException { - throw new UnsupportedOperationException("this codec can only be used for reading"); - } - }; + private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat(); // 3.x doesn't support docvalues private final DocValuesFormat docValuesFormat = new DocValuesFormat() { Index: lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (revision 1378691) +++ lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -380,12 +380,13 @@ if (!segmentWasUpgraded(directory, si)) { + String markerFileName = IndexFileNames.segmentFileName(si.name, "upgraded", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION); + si.addFile(markerFileName); + final String segmentFileName = write3xInfo(directory, si, IOContext.DEFAULT); upgradedSIFiles.add(segmentFileName); directory.sync(Collections.singletonList(segmentFileName)); - String markerFileName = IndexFileNames.segmentFileName(si.name, "upgraded", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION); - // Write separate marker file indicating upgrade // is completed. This way, if there is a JVM // kill/crash, OS crash, power loss, etc. while