Skip to content

Add index version check retrospectively. #132560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private static Version parseUnchecked(String version) {
public static final IndexVersion SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT = def(9_031_0_00, Version.LUCENE_10_2_2);
public static final IndexVersion DEFAULT_DENSE_VECTOR_TO_BBQ_HNSW = def(9_032_0_00, Version.LUCENE_10_2_2);
public static final IndexVersion MATCH_ONLY_TEXT_STORED_AS_BYTES = def(9_033_0_00, Version.LUCENE_10_2_2);
public static final IndexVersion USE_819_TSDB_DOC_VALUES_FORMAT = def(9_034_0_00, Version.LUCENE_10_2_2);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.codec.bloomfilter.ES87BloomFilterPostingsFormat;
import org.elasticsearch.index.codec.postings.ES812PostingsFormat;
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat;
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat;
import org.elasticsearch.index.mapper.CompletionFieldMapper;
import org.elasticsearch.index.mapper.IdFieldMapper;
Expand All @@ -35,14 +36,16 @@ public class PerFieldFormatSupplier {

private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
private static final ES87TSDBDocValuesFormat es87TsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
private static final ES819TSDBDocValuesFormat es819TsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
private static final PostingsFormat completionPostingsFormat = PostingsFormat.forName("Completion101");

private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
private final MapperService mapperService;

private final PostingsFormat defaultPostingsFormat;
private final DocValuesFormat defaultTsdbDocValuesFormat;

public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays) {
this.mapperService = mapperService;
Expand All @@ -56,6 +59,12 @@ public PerFieldFormatSupplier(MapperService mapperService, BigArrays bigArrays)
// our own posting format using PFOR
defaultPostingsFormat = es812PostingsFormat;
}
if (mapperService != null
&& mapperService.getIndexSettings().getIndexVersionCreated().onOrAfter(IndexVersions.USE_819_TSDB_DOC_VALUES_FORMAT)) {
defaultTsdbDocValuesFormat = es819TsdbDocValuesFormat;
} else {
defaultTsdbDocValuesFormat = es87TsdbDocValuesFormat;
}
}

public PostingsFormat getPostingsFormatForField(String field) {
Expand Down Expand Up @@ -106,7 +115,7 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {

public DocValuesFormat getDocValuesFormatForField(String field) {
if (useTSDBDocValuesFormat(field)) {
return tsdbDocValuesFormat;
return defaultTsdbDocValuesFormat;
}
return docValuesFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ES87TSDBDocValuesFormat(int skipIndexIntervalSize) {

@Override
public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
throw new UnsupportedOperationException("writing es87 doc values is no longer supported");
return new ES87TSDBDocValuesConsumer(state, skipIndexIntervalSize, DATA_CODEC, DATA_EXTENSION, META_CODEC, META_EXTENSION);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;

import java.io.IOException;

Expand Down Expand Up @@ -139,4 +141,9 @@ public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOExcept
public DocValuesProducer fieldsProducer(SegmentReadState state) throws IOException {
return new ES819TSDBDocValuesProducer(state, DATA_CODEC, DATA_EXTENSION, META_CODEC, META_EXTENSION);
}

public static ES819TSDBDocValuesFormat load(IndexVersion indexVersion) {
boolean enableOptimizedMerge = indexVersion.onOrAfter(IndexVersions.USE_819_TSDB_DOC_VALUES_FORMAT);
return new ES819TSDBDocValuesFormat(DEFAULT_SKIP_INDEX_INTERVAL_SIZE, enableOptimizedMerge);
}
}