Skip to content

Commit 155fe96

Browse files
authored
Enable large numeric blocks for TSDB (#138744)
* Enable large numeric blocks for TSDB * test fix * fix sync issue * comments * fix test
1 parent 539645d commit 155fe96

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
209209
IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING,
210210
IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING,
211211
IndexSettings.USE_TIME_SERIES_DOC_VALUES_FORMAT_SETTING,
212+
IndexSettings.USE_TIME_SERIES_DOC_VALUES_FORMAT_LARGE_BLOCK_SIZE,
212213
InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT,
213214
IndexSettings.USE_ES_812_POSTINGS_FORMAT,
214215

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,19 @@ public Iterator<Setting<?>> settings() {
842842
Property.Final
843843
);
844844

845+
public static final Setting<Boolean> USE_TIME_SERIES_DOC_VALUES_FORMAT_LARGE_BLOCK_SIZE = Setting.boolSetting(
846+
"index.use_time_series_doc_values_format_large_block_size",
847+
settings -> {
848+
if (settings == null) {
849+
return Boolean.FALSE.toString();
850+
}
851+
var indexMode = IndexSettings.MODE.get(settings);
852+
return Boolean.toString(indexMode == IndexMode.TIME_SERIES);
853+
},
854+
Property.IndexScope,
855+
Property.Final
856+
);
857+
845858
/**
846859
* Legacy index setting, kept for 7.x BWC compatibility. This setting has no effect in 8.x. Do not use.
847860
* TODO: Remove in 9.0
@@ -1021,6 +1034,7 @@ private void setRetentionLeaseMillis(final TimeValue retentionLease) {
10211034
private final boolean useDocValuesSkipper;
10221035
private final boolean useTimeSeriesSyntheticId;
10231036
private final boolean useTimeSeriesDocValuesFormat;
1037+
private final boolean useTimeSeriesDocValuesFormatLargeBlockSize;
10241038
private final boolean useEs812PostingsFormat;
10251039

10261040
/**
@@ -1210,6 +1224,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
12101224
useDocValuesSkipper = DOC_VALUES_SKIPPER && scopedSettings.get(USE_DOC_VALUES_SKIPPER);
12111225
seqNoIndexOptions = scopedSettings.get(SEQ_NO_INDEX_OPTIONS_SETTING);
12121226
useTimeSeriesDocValuesFormat = scopedSettings.get(USE_TIME_SERIES_DOC_VALUES_FORMAT_SETTING);
1227+
useTimeSeriesDocValuesFormatLargeBlockSize = scopedSettings.get(USE_TIME_SERIES_DOC_VALUES_FORMAT_LARGE_BLOCK_SIZE);
12131228
useEs812PostingsFormat = scopedSettings.get(USE_ES_812_POSTINGS_FORMAT);
12141229
final var useSyntheticId = IndexSettings.TSDB_SYNTHETIC_ID_FEATURE_FLAG && scopedSettings.get(USE_SYNTHETIC_ID);
12151230
if (indexMetadata.useTimeSeriesSyntheticId() != useSyntheticId) {
@@ -1988,6 +2003,13 @@ public boolean useTimeSeriesDocValuesFormat() {
19882003
return useTimeSeriesDocValuesFormat;
19892004
}
19902005

2006+
/**
2007+
* @return Whether the time series doc value format with large numeric block size should be used.
2008+
*/
2009+
public boolean isUseTimeSeriesDocValuesFormatLargeBlockSize() {
2010+
return useTimeSeriesDocValuesFormatLargeBlockSize;
2011+
}
2012+
19912013
/**
19922014
* @return Whether the ES 8.12 postings format should be used.
19932015
*/

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesFormat;
1616
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
1717
import org.elasticsearch.common.util.BigArrays;
18+
import org.elasticsearch.common.util.FeatureFlag;
1819
import org.elasticsearch.index.IndexMode;
1920
import org.elasticsearch.index.IndexSettings;
2021
import org.elasticsearch.index.IndexVersions;
@@ -43,6 +44,8 @@ public class PerFieldFormatSupplier {
4344
private static final Set<String> INCLUDE_META_FIELDS;
4445
private static final Set<String> EXCLUDE_MAPPER_TYPES;
4546

47+
private static final boolean TSDB_USE_LARGE_NUMERIC_BLOCKS = new FeatureFlag("tsdb_large_numeric_blocks").isEnabled();
48+
4649
static {
4750
// TODO: should we just allow all fields to use tsdb doc values codec?
4851
// Avoid using tsdb codec for fields like _seq_no, _primary_term.
@@ -59,7 +62,10 @@ public class PerFieldFormatSupplier {
5962

6063
private static final DocValuesFormat docValuesFormat = new Lucene90DocValuesFormat();
6164
private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
62-
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormat = new ES819TSDBDocValuesFormat();
65+
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormat = ES819TSDBDocValuesFormat.getInstance(false);
66+
private static final ES819TSDBDocValuesFormat tsdbDocValuesFormatLargeNumericBlock = ES819TSDBDocValuesFormat.getInstance(
67+
TSDB_USE_LARGE_NUMERIC_BLOCKS
68+
);
6369
private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
6470
private static final PostingsFormat completionPostingsFormat = PostingsFormat.forName("Completion101");
6571

@@ -137,7 +143,9 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
137143

138144
public DocValuesFormat getDocValuesFormatForField(String field) {
139145
if (useTSDBDocValuesFormat(field)) {
140-
return tsdbDocValuesFormat;
146+
return (mapperService != null && mapperService.getIndexSettings().isUseTimeSeriesDocValuesFormatLargeBlockSize())
147+
? tsdbDocValuesFormatLargeNumericBlock
148+
: tsdbDocValuesFormat;
141149
}
142150
return docValuesFormat;
143151
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ private static boolean getOptimizedMergeEnabledDefault() {
140140
final BinaryDVCompressionMode binaryDVCompressionMode;
141141
final boolean enablePerBlockCompression;
142142

143+
public static ES819TSDBDocValuesFormat getInstance(boolean useLargeNumericBlock) {
144+
return useLargeNumericBlock ? new ES819TSDBDocValuesFormat(NUMERIC_LARGE_BLOCK_SHIFT) : new ES819TSDBDocValuesFormat();
145+
}
146+
143147
public ES819TSDBDocValuesFormat() {
144148
this(NUMERIC_BLOCK_SHIFT);
145149
}

0 commit comments

Comments
 (0)