Apache Lucene open-source search software
LUCENE-5611: fix dv exceptions to be non-aborting
Robert Muirb5171bb66885
diff --git a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.javaindex f093901f9c6..5d0d6726e9a 100644--- a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java+++ b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java@@ -293,34 +293,63 @@ final class DefaultIndexingChain extends DocConsumer {}// Add stored fields:+ // TODO: if these hit exc today ->>> corrumption!fillStoredFields(docState.docID);storedFieldsWriter.startDocument();lastStoredDocID++;- success = false;- try {- for (StorableField field : docState.doc.storableFields()) {- final String fieldName = field.name();- IndexableFieldType fieldType = field.fieldType();-+ // TODO: clean up this looop, its complicated because dv exceptions are non-aborting,+ // but storedfields are. Its also bogus that docvalues are treated as stored fields...+ for (StorableField field : docState.doc.storableFields()) {+ final String fieldName = field.name();+ IndexableFieldType fieldType = field.fieldType();+ PerField fp = null;++ success = false;+ try {+ // TODO: make this non-aborting and change the test to confirm that!!!verifyFieldType(fieldName, fieldType);-- PerField fp = getOrAddField(fieldName, fieldType, false);++ fp = getOrAddField(fieldName, fieldType, false);if (fieldType.stored()) {storedFieldsWriter.writeField(fp.fieldInfo, field);}-+ success = true;+ } finally {+ if (!success) {+ docWriter.setAborting();+ }+ }++ success = false;+ try {DocValuesType dvType = fieldType.docValueType();if (dvType != null) {indexDocValue(fp, dvType, field);}+ success = true;+ } finally {+ if (!success) {+ // dv failed: so just try to bail on the current doc by calling finishDocument()...+ success = false;+ try {+ storedFieldsWriter.finishDocument();+ success = true;+ } finally {+ if (!success) {+ docWriter.setAborting();+ }+ }+ }}+ }++ success = false;+ try {storedFieldsWriter.finishDocument();success = true;} finally {- if (success == false) {- // We must abort, on the possibility that the- // stored fields file is now corrupt:+ if (!success) {docWriter.setAborting();}}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.javaindex 923566bc08e..0b2c582710e 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java@@ -43,6 +43,7 @@ import org.apache.lucene.util.LuceneTestCase;* Tests DocValues integration into IndexWriter**/+// TODO: fix all tests in here to ensure dv exceptions are non-abortingpublic class TestDocValuesIndexing extends LuceneTestCase {/** - add test for multi segment case with deletes@@ -92,10 +93,14 @@ public class TestDocValuesIndexing extends LuceneTestCase {RandomIndexWriter w = new RandomIndexWriter(random(), d);Document doc = new Document();Field f = new NumericDocValuesField("field", 17);+ doc.add(f);++ // add the doc+ w.addDocument(doc);+// Index doc values are single-valued so we should not// be able to add same field more than once:doc.add(f);- doc.add(f);try {w.addDocument(doc);fail("didn't hit expected exception");@@ -103,10 +108,6 @@ public class TestDocValuesIndexing extends LuceneTestCase {// expected}- doc = new Document();- doc.add(f);- w.addDocument(doc);- w.forceMerge(1);DirectoryReader r = w.getReader();w.shutdown();assertEquals(17, FieldCache.DEFAULT.getInts(getOnlySegmentReader(r), "field", false).get(0));