mirror of https://github.com/apache/lucene.git
LUCENE-8134: Fix validation of index options.
There were test failures in case inconsistent index options were introduced in a new segment because checks were not done in the right order.
This commit is contained in:
parent
a2eb1dc271
commit
34d3282ede
|
@ -637,11 +637,11 @@ final class DefaultIndexingChain extends DocConsumer {
|
|||
// Messy: must set this here because e.g. FreqProxTermsWriterPerField looks at the initial
|
||||
// IndexOptions to decide what arrays it must create).
|
||||
assert info.getIndexOptions() == IndexOptions.NONE;
|
||||
info.setIndexOptions(indexOptions);
|
||||
// This is the first time we are seeing this field indexed, so we now
|
||||
// record the index options so that any future attempt to (illegally)
|
||||
// change the index options of this field, will throw an IllegalArgExc:
|
||||
fieldInfos.globalFieldNumbers.setIndexOptions(info.number, info.name, indexOptions);
|
||||
info.setIndexOptions(indexOptions);
|
||||
}
|
||||
|
||||
/** NOTE: not static: accesses at least docState, termsHash. */
|
||||
|
|
|
@ -296,7 +296,7 @@ public class FieldInfos implements Iterable<FieldInfo> {
|
|||
}
|
||||
IndexOptions currentIndexOptions = this.indexOptions.get(name);
|
||||
if (indexOptions != IndexOptions.NONE && currentIndexOptions != null && currentIndexOptions != IndexOptions.NONE && indexOptions != currentIndexOptions) {
|
||||
throw new IllegalArgumentException("cannot change index options from " + currentIndexOptions + " to " + indexOptions + " for field \"" + name + "\"");
|
||||
throw new IllegalArgumentException("cannot change field \"" + name + "\" from index options=" + currentIndexOptions + " to inconsistent index options=" + indexOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,21 +33,29 @@ public class TestIndexOptions extends LuceneTestCase {
|
|||
for (IndexOptions from : IndexOptions.values()) {
|
||||
for (IndexOptions to : IndexOptions.values()) {
|
||||
for (boolean preExisting : new boolean[] { false, true }) {
|
||||
doTestChangeIndexOptionsViaAddDocument(preExisting, from, to);
|
||||
for (boolean onNewSegment : new boolean[] { false, true }) {
|
||||
doTestChangeIndexOptionsViaAddDocument(preExisting, onNewSegment, from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestChangeIndexOptionsViaAddDocument(boolean preExistingField, IndexOptions from, IndexOptions to) throws IOException {
|
||||
private void doTestChangeIndexOptionsViaAddDocument(boolean preExistingField, boolean onNewSegment, IndexOptions from, IndexOptions to) throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
|
||||
if (preExistingField) {
|
||||
w.addDocument(Collections.singleton(new IntPoint("foo", 1)));
|
||||
if (onNewSegment) {
|
||||
DirectoryReader.open(w).close();
|
||||
}
|
||||
}
|
||||
FieldType ft1 = new FieldType(TextField.TYPE_STORED);
|
||||
ft1.setIndexOptions(from);
|
||||
w.addDocument(Collections.singleton(new Field("foo", "bar", ft1)));
|
||||
if (onNewSegment) {
|
||||
DirectoryReader.open(w).close();
|
||||
}
|
||||
FieldType ft2 = new FieldType(TextField.TYPE_STORED);
|
||||
ft2.setIndexOptions(to);
|
||||
if (from == IndexOptions.NONE || to == IndexOptions.NONE || from == to) {
|
||||
|
|
Loading…
Reference in New Issue