Skip to content

Commit ded314b

Browse files
committed
Add index version check retrospectively.
1 parent 89f01ed commit ded314b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private static Version parseUnchecked(String version) {
180180
public static final IndexVersion SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT = def(9_031_0_00, Version.LUCENE_10_2_2);
181181
public static final IndexVersion DEFAULT_DENSE_VECTOR_TO_BBQ_HNSW = def(9_032_0_00, Version.LUCENE_10_2_2);
182182
public static final IndexVersion MATCH_ONLY_TEXT_STORED_AS_BYTES = def(9_033_0_00, Version.LUCENE_10_2_2);
183+
public static final IndexVersion USE_819_TSDB_DOC_VALUES_FORMAT = def(9_0334_0_00, Version.LUCENE_10_2_2);
183184

184185
/*
185186
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/index/codec/PerFieldFormatSupplier.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.index.IndexVersions;
2121
import org.elasticsearch.index.codec.bloomfilter.ES87BloomFilterPostingsFormat;
2222
import org.elasticsearch.index.codec.postings.ES812PostingsFormat;
23+
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat;
2324
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat;
2425
import org.elasticsearch.index.mapper.CompletionFieldMapper;
2526
import org.elasticsearch.index.mapper.IdFieldMapper;
@@ -35,14 +36,16 @@ public class PerFieldFormatSupplier {
3536

3637
private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
3738
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
38-
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
39+
private static final ES87TSDBDocValuesFormat es87TsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
40+
private static final ES819TSDBDocValuesFormat es819TsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
3941
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
4042
private static final PostingsFormat completionPostingsFormat = PostingsFormat.forName("Completion101");
4143

4244
private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
4345
private final MapperService mapperService;
4446

4547
private final PostingsFormat defaultPostingsFormat;
48+
private final DocValuesFormat defaultTsdbDocValuesFormat;
4649

4750
public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays) {
4851
this.mapperService = mapperService;
@@ -56,6 +59,12 @@ public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays)
5659
// our own posting format using PFOR
5760
defaultPostingsFormat = es812PostingsFormat;
5861
}
62+
if (mapperService != null
63+
&& mapperService.getIndexSettings().getIndexVersionCreated().onOrAfter(IndexVersions.USE_819_TSDB_DOC_VALUES_FORMAT)) {
64+
defaultTsdbDocValuesFormat = es819TsdbDocValuesFormat;
65+
} else {
66+
defaultTsdbDocValuesFormat = es87TsdbDocValuesFormat;
67+
}
5968
}
6069

6170
public PostingsFormat getPostingsFormatForField(String field) {
@@ -106,7 +115,7 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
106115

107116
public DocValuesFormat getDocValuesFormatForField(String field) {
108117
if (useTSDBDocValuesFormat(field)) {
109-
return tsdbDocValuesFormat;
118+
return defaultTsdbDocValuesFormat;
110119
}
111120
return docValuesFormat;
112121
}

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormat.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.apache.lucene.index.SegmentReadState;
1515
import org.apache.lucene.index.SegmentWriteState;
1616
import org.elasticsearch.core.SuppressForbidden;
17+
import org.elasticsearch.index.IndexVersion;
18+
import org.elasticsearch.index.IndexVersions;
1719

1820
import java.io.IOException;
1921

@@ -139,4 +141,9 @@ public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOExcept
139141
public DocValuesProducer fieldsProducer(SegmentReadState state) throws IOException {
140142
return new ES819TSDBDocValuesProducer(state, DATA_CODEC, DATA_EXTENSION, META_CODEC, META_EXTENSION);
141143
}
144+
145+
public static ES819TSDBDocValuesFormat load(IndexVersion indexVersion) {
146+
boolean enableOptimizedMerge = indexVersion.onOrAfter(IndexVersions.USE_819_TSDB_DOC_VALUES_FORMAT);
147+
return new ES819TSDBDocValuesFormat(DEFAULT_SKIP_INDEX_INTERVAL_SIZE, enableOptimizedMerge);
148+
}
142149
}

0 commit comments

Comments
 (0)