From 481139b490127afcc58bfe25e9a668fbc65d8cdd Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 1 Feb 2013 21:38:01 +0000 Subject: [PATCH] fix nocommits git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1441644 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/FieldInfos.java | 29 ++--- .../lucene/index/TestDocValuesIndexing.java | 107 +++++++++++++++++- 2 files changed, 115 insertions(+), 21 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java index 528a164db56..262501b1584 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java @@ -163,7 +163,14 @@ public class FieldInfos implements Iterable { private final Map numberToName; private final Map nameToNumber; + // We use this to enforce that a given field never + // changes DV type, even across segments / IndexWriter + // sessions: private final Map docValuesType; + + // TODO: we should similarly catch an attempt to turn + // norms back on after they were already ommitted; today + // we silently discard the norm but this is badly trappy private int lowestUnassignedFieldNumber = -1; FieldNumbers() { @@ -209,26 +216,8 @@ public class FieldInfos implements Iterable { return fieldNumber.intValue(); } - /** - * Sets the given field number and name if not yet set. - */ - // nocommit: why is docvalues involved with global field numbers? - // nocommit: and is it even tested... - /* - synchronized void setIfNotSet(int fieldNumber, String fieldName, DocValuesType dvType) { - final Integer boxedFieldNumber = Integer.valueOf(fieldNumber); - if (!numberToName.containsKey(boxedFieldNumber) - && !nameToNumber.containsKey(fieldName) - && !docValuesType.containsKey(dvType)) { - numberToName.put(boxedFieldNumber, fieldName); - nameToNumber.put(fieldName, boxedFieldNumber); - docValuesType.put(fieldName, dvType); - } else { - // nocommit should this be a real check? - assert containsConsistent(boxedFieldNumber, fieldName, dvType); - } - } - */ + // nocommit: do we need better tests for attempt to + // change doc value type across segments... // used by assert synchronized boolean containsConsistent(Integer number, String name, DocValuesType dvType) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java index bdd5defa08b..380799d3ce5 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java @@ -610,11 +610,116 @@ public class TestDocValuesIndexing extends LuceneTestCase { writer.close(); conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE); writer = new IndexWriter(dir, conf); - writer.deleteAll(); doc = new Document(); doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); writer.addDocument(doc); writer.close(); dir.close(); } + + public void testTypeChangeViaAddIndexes() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + IndexWriter writer = new IndexWriter(dir, conf); + Document doc = new Document(); + doc.add(new NumericDocValuesField("dv", 0L)); + writer.addDocument(doc); + writer.close(); + + Directory dir2 = newDirectory(); + writer = new IndexWriter(dir2, conf); + doc = new Document(); + doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); + writer.addDocument(doc); + try { + writer.addIndexes(dir); + fail("did not hit exception"); + } catch (IllegalArgumentException iae) { + // expected + } + writer.close(); + + dir.close(); + dir2.close(); + } + + public void testTypeChangeViaAddIndexesIR() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + IndexWriter writer = new IndexWriter(dir, conf); + Document doc = new Document(); + doc.add(new NumericDocValuesField("dv", 0L)); + writer.addDocument(doc); + writer.close(); + + Directory dir2 = newDirectory(); + writer = new IndexWriter(dir2, conf); + doc = new Document(); + doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); + writer.addDocument(doc); + IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)}; + try { + writer.addIndexes(readers); + fail("did not hit exception"); + } catch (IllegalArgumentException iae) { + // expected + } + readers[0].close(); + writer.close(); + + dir.close(); + dir2.close(); + } + + public void testTypeChangeViaAddIndexes2() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + IndexWriter writer = new IndexWriter(dir, conf); + Document doc = new Document(); + doc.add(new NumericDocValuesField("dv", 0L)); + writer.addDocument(doc); + writer.close(); + + Directory dir2 = newDirectory(); + writer = new IndexWriter(dir2, conf); + writer.addIndexes(dir); + doc = new Document(); + doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); + try { + writer.addDocument(doc); + fail("did not hit exception"); + } catch (IllegalArgumentException iae) { + // expected + } + writer.close(); + dir2.close(); + dir.close(); + } + + public void testTypeChangeViaAddIndexesIR2() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + IndexWriter writer = new IndexWriter(dir, conf); + Document doc = new Document(); + doc.add(new NumericDocValuesField("dv", 0L)); + writer.addDocument(doc); + writer.close(); + + Directory dir2 = newDirectory(); + writer = new IndexWriter(dir2, conf); + IndexReader[] readers = new IndexReader[] {DirectoryReader.open(dir)}; + writer.addIndexes(readers); + readers[0].close(); + doc = new Document(); + doc.add(new SortedDocValuesField("dv", new BytesRef("foo"))); + try { + writer.addDocument(doc); + fail("did not hit exception"); + } catch (IllegalArgumentException iae) { + // expected + } + writer.close(); + dir2.close(); + dir.close(); + } }