Skip to content

Commit c55a460

Browse files
authored
Add doc values support for ES 5 and ES 6 (#82207)
Adds support for reading doc values formats of ES 5 and 6. Relates #81210
1 parent b118d84 commit c55a460

24 files changed

+4483
-47
lines changed

x-pack/plugin/old-lucene-versions/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ dependencies {
1313
compileOnly project(path: xpackModule('core'))
1414
}
1515

16-
test.enabled = false
17-
1816
addQaCheckDependencies()

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/OldLuceneVersions.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private static void convertToNewFormat(IndexShard indexShard) {
7171

7272
private static SegmentInfos convertToNewerLuceneVersion(OldSegmentInfos oldSegmentInfos) {
7373
final SegmentInfos segmentInfos = new SegmentInfos(org.apache.lucene.util.Version.LATEST.major);
74+
segmentInfos.version = oldSegmentInfos.version;
75+
segmentInfos.counter = oldSegmentInfos.counter;
7476
segmentInfos.setNextWriteGeneration(oldSegmentInfos.getGeneration() + 1);
7577
final Map<String, String> map = new HashMap<>(oldSegmentInfos.getUserData());
7678
if (map.containsKey(Engine.HISTORY_UUID_KEY) == false) {
@@ -85,21 +87,21 @@ private static SegmentInfos convertToNewerLuceneVersion(OldSegmentInfos oldSegme
8587
if (map.containsKey(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID) == false) {
8688
map.put(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID, "-1");
8789
}
88-
segmentInfos.setUserData(map, true);
90+
segmentInfos.setUserData(map, false);
8991
for (SegmentCommitInfo infoPerCommit : oldSegmentInfos.asList()) {
9092
final SegmentInfo newInfo = BWCCodec.wrap(infoPerCommit.info);
91-
92-
segmentInfos.add(
93-
new SegmentCommitInfo(
94-
newInfo,
95-
infoPerCommit.getDelCount(),
96-
infoPerCommit.getSoftDelCount(),
97-
infoPerCommit.getDelGen(),
98-
infoPerCommit.getFieldInfosGen(),
99-
infoPerCommit.getDocValuesGen(),
100-
infoPerCommit.getId()
101-
)
93+
final SegmentCommitInfo commitInfo = new SegmentCommitInfo(
94+
newInfo,
95+
infoPerCommit.getDelCount(),
96+
infoPerCommit.getSoftDelCount(),
97+
infoPerCommit.getDelGen(),
98+
infoPerCommit.getFieldInfosGen(),
99+
infoPerCommit.getDocValuesGen(),
100+
infoPerCommit.getId()
102101
);
102+
commitInfo.setDocValuesUpdatesFiles(infoPerCommit.getDocValuesUpdatesFiles());
103+
commitInfo.setFieldInfosFiles(infoPerCommit.getFieldInfosFiles());
104+
segmentInfos.add(commitInfo);
103105
}
104106
return segmentInfos;
105107
}

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/BWCCodec.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.apache.lucene.backward_codecs.lucene70.Lucene70Codec;
1111
import org.apache.lucene.codecs.Codec;
12-
import org.apache.lucene.codecs.DocValuesFormat;
1312
import org.apache.lucene.codecs.FieldInfosFormat;
1413
import org.apache.lucene.codecs.FieldsConsumer;
1514
import org.apache.lucene.codecs.FieldsProducer;
@@ -20,7 +19,6 @@
2019
import org.apache.lucene.codecs.PostingsFormat;
2120
import org.apache.lucene.codecs.SegmentInfoFormat;
2221
import org.apache.lucene.codecs.TermVectorsFormat;
23-
import org.apache.lucene.index.DocValuesType;
2422
import org.apache.lucene.index.FieldInfo;
2523
import org.apache.lucene.index.FieldInfos;
2624
import org.apache.lucene.index.Fields;
@@ -31,7 +29,6 @@
3129
import org.apache.lucene.index.Terms;
3230
import org.apache.lucene.store.Directory;
3331
import org.apache.lucene.store.IOContext;
34-
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
3532
import org.elasticsearch.xpack.lucene.bwc.codecs.lucene70.BWCLucene70Codec;
3633

3734
import java.io.IOException;
@@ -60,11 +57,6 @@ public NormsFormat normsFormat() {
6057
throw new UnsupportedOperationException();
6158
}
6259

63-
@Override
64-
public DocValuesFormat docValuesFormat() {
65-
throw new UnsupportedOperationException();
66-
}
67-
6860
@Override
6961
public TermVectorsFormat termVectorsFormat() {
7062
throw new UnsupportedOperationException();
@@ -166,14 +158,10 @@ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSu
166158
};
167159
}
168160

169-
// mark all fields as having no postings, no doc values, and no points.
161+
// mark all fields as having no postings, no term vectors, no norms, no payloads, no points, and no vectors.
170162
private static FieldInfos filterFields(FieldInfos fieldInfos) {
171163
List<FieldInfo> fieldInfoCopy = new ArrayList<>(fieldInfos.size());
172164
for (FieldInfo fieldInfo : fieldInfos) {
173-
// omit sequence number field so that it doesn't interfere with peer recovery
174-
if (fieldInfo.name.equals(SeqNoFieldMapper.NAME)) {
175-
continue;
176-
}
177165
fieldInfoCopy.add(
178166
new FieldInfo(
179167
fieldInfo.name,
@@ -182,8 +170,8 @@ private static FieldInfos filterFields(FieldInfos fieldInfos) {
182170
false,
183171
false,
184172
IndexOptions.NONE,
185-
DocValuesType.NONE,
186-
-1,
173+
fieldInfo.getDocValuesType(),
174+
fieldInfo.getDocValuesGen(),
187175
fieldInfo.attributes(),
188176
0,
189177
0,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @notice
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Modifications copyright (C) 2021 Elasticsearch B.V.
19+
*/
20+
package org.elasticsearch.xpack.lucene.bwc.codecs.index;
21+
22+
import org.apache.lucene.index.BinaryDocValues;
23+
import org.apache.lucene.util.BytesRef;
24+
25+
/**
26+
* A per-document byte[]
27+
*
28+
* @deprecated Use {@link BinaryDocValues} instead.
29+
*/
30+
@Deprecated
31+
public abstract class LegacyBinaryDocValues {
32+
33+
/** Sole constructor. (For invocation by subclass
34+
* constructors, typically implicit.) */
35+
protected LegacyBinaryDocValues() {}
36+
37+
/** Lookup the value for document. The returned {@link BytesRef} may be
38+
* re-used across calls to {@link #get(int)} so make sure to
39+
* {@link BytesRef#deepCopyOf(BytesRef) copy it} if you want to keep it
40+
* around. */
41+
public abstract BytesRef get(int docID);
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* @notice
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Modifications copyright (C) 2021 Elasticsearch B.V.
19+
*/
20+
package org.elasticsearch.xpack.lucene.bwc.codecs.index;
21+
22+
import org.apache.lucene.index.BinaryDocValues;
23+
import org.apache.lucene.util.Bits;
24+
import org.apache.lucene.util.BytesRef;
25+
26+
import java.io.IOException;
27+
28+
/**
29+
* Wraps a {@link LegacyBinaryDocValues} into a {@link BinaryDocValues}.
30+
*
31+
* @deprecated Implement {@link BinaryDocValues} directly.
32+
*/
33+
@Deprecated
34+
public final class LegacyBinaryDocValuesWrapper extends BinaryDocValues {
35+
private final Bits docsWithField;
36+
private final LegacyBinaryDocValues values;
37+
private final int maxDoc;
38+
private int docID = -1;
39+
40+
public LegacyBinaryDocValuesWrapper(Bits docsWithField, LegacyBinaryDocValues values) {
41+
this.docsWithField = docsWithField;
42+
this.values = values;
43+
this.maxDoc = docsWithField.length();
44+
}
45+
46+
@Override
47+
public int docID() {
48+
return docID;
49+
}
50+
51+
@Override
52+
public int nextDoc() {
53+
docID++;
54+
while (docID < maxDoc) {
55+
if (docsWithField.get(docID)) {
56+
return docID;
57+
}
58+
docID++;
59+
}
60+
docID = NO_MORE_DOCS;
61+
return NO_MORE_DOCS;
62+
}
63+
64+
@Override
65+
public int advance(int target) {
66+
if (target < docID) {
67+
throw new IllegalArgumentException("cannot advance backwards: docID=" + docID + " target=" + target);
68+
}
69+
if (target == NO_MORE_DOCS) {
70+
this.docID = NO_MORE_DOCS;
71+
} else {
72+
this.docID = target - 1;
73+
nextDoc();
74+
}
75+
return docID;
76+
}
77+
78+
@Override
79+
public boolean advanceExact(int target) throws IOException {
80+
docID = target;
81+
return docsWithField.get(target);
82+
}
83+
84+
@Override
85+
public long cost() {
86+
return 0;
87+
}
88+
89+
@Override
90+
public BytesRef binaryValue() {
91+
return values.get(docID);
92+
}
93+
}

0 commit comments

Comments
 (0)