Skip to content

Apache Lucene open-source search software

LUCENE-5192: use syn'd method to set field's DV type

Michael McCandlessda8ab682c6da
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 0ca0882e6d7..25d4838c455 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
@@ -228,6 +228,11 @@ public class FieldInfos implements Iterable<FieldInfo> {
nameToNumber.clear();
docValuesType.clear();
}
+
+ synchronized void setDocValuesType(int number, String name, DocValuesType dvType) {
+ assert containsConsistent(number, name, dvType);
+ docValuesType.put(name, dvType);
+ }
}
static final class Builder {
@@ -287,9 +292,14 @@ public class FieldInfos implements Iterable<FieldInfo> {
fi.update(isIndexed, storeTermVector, omitNorms, storePayloads, indexOptions);
if (docValues != null) {
- fi.setDocValuesType(docValues);
- // must also update docValuesType map so it's aware of this field's DocValueType
- globalFieldNumbers.docValuesType.put(name, docValues);
+ // only pay the synchronization cost if fi does not already have a DVType
+ boolean updateGlobal = !fi.hasDocValues();
+ fi.setDocValuesType(docValues); // this will also perform the consistency check.
+ if (updateGlobal) {
+ // must also update docValuesType map so it's
+ // aware of this field's DocValueType
+ globalFieldNumbers.setDocValuesType(fi.number, name, docValues);
+ }
}
if (!fi.omitsNorms() && normType != null) {