Skip to content

Commit e61b8c2

Browse files
committed
Add feature flag for binary dv compression
1 parent 982386e commit e61b8c2

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.codecs.DocValuesProducer;
1414
import org.apache.lucene.index.SegmentReadState;
1515
import org.apache.lucene.index.SegmentWriteState;
16+
import org.elasticsearch.common.util.FeatureFlag;
1617
import org.elasticsearch.core.SuppressForbidden;
1718
import org.elasticsearch.index.codec.tsdb.BinaryDVCompressionMode;
1819

@@ -36,6 +37,8 @@
3637
*/
3738
public class ES819TSDBDocValuesFormat extends org.apache.lucene.codecs.DocValuesFormat {
3839

40+
public static final boolean BINARY_DV_COMPRESSION_FEATURE_FLAG = new FeatureFlag("binary_dv_compression").isEnabled();
41+
3942
static final int NUMERIC_BLOCK_SHIFT = 7;
4043
public static final int NUMERIC_BLOCK_SIZE = 1 << NUMERIC_BLOCK_SHIFT;
4144
static final int NUMERIC_BLOCK_MASK = NUMERIC_BLOCK_SIZE - 1;
@@ -135,7 +138,7 @@ public ES819TSDBDocValuesFormat() {
135138
DEFAULT_SKIP_INDEX_INTERVAL_SIZE,
136139
ORDINAL_RANGE_ENCODING_MIN_DOC_PER_ORDINAL,
137140
OPTIMIZED_MERGE_ENABLE_DEFAULT,
138-
BinaryDVCompressionMode.COMPRESSED_ZSTD_LEVEL_1
141+
BINARY_DV_COMPRESSION_FEATURE_FLAG ? BinaryDVCompressionMode.COMPRESSED_ZSTD_LEVEL_1 : BinaryDVCompressionMode.NO_COMPRESS
139142
);
140143
}
141144

server/src/test/java/org/elasticsearch/index/codec/tsdb/TsdbDocValueBwcTests.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.codecs.Codec;
1313
import org.apache.lucene.codecs.DocValuesFormat;
1414
import org.apache.lucene.codecs.DocValuesProducer;
15+
import org.apache.lucene.document.BinaryDocValuesField;
1516
import org.apache.lucene.document.Document;
1617
import org.apache.lucene.document.LongPoint;
1718
import org.apache.lucene.document.NumericDocValuesField;
@@ -72,6 +73,13 @@ public void testMixedIndexDocValueVersion0ToVersion1() throws Exception {
7273
testMixedIndex(oldCodec, newCodec, this::assertVersion819, this::assertVersion819);
7374
}
7475

76+
public void testMixedIndexDocValueBinaryCompressionFeatureDisabledOldCodec() throws Exception {
77+
// Mimic the behavior of BINARY_DV_COMPRESSION_FEATURE_FLAG being disabled in the oldCodec, but enabled in the newCodec.
78+
var oldCodec = TestUtil.alwaysDocValuesFormat(new ES819TSDBDocValuesFormat(BinaryDVCompressionMode.NO_COMPRESS));
79+
var newCodec = TestUtil.alwaysDocValuesFormat(new ES819TSDBDocValuesFormat(BinaryDVCompressionMode.COMPRESSED_ZSTD_LEVEL_1));
80+
testMixedIndex(oldCodec, newCodec, this::assertVersion819, this::assertVersion819);
81+
}
82+
7583
public void testMixedIndex816To900Lucene101() throws Exception {
7684
var oldCodec = new Elasticsearch816Codec() {
7785

@@ -151,8 +159,9 @@ void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersi
151159
d.add(new SortedNumericDocValuesField(timestampField, timestamp++));
152160

153161
if (r % 10 < 8) {
154-
// Most of the time store counter:
162+
// Most of the time store counter and binary value:
155163
d.add(new NumericDocValuesField("counter_1", counter1++));
164+
d.add(new BinaryDocValuesField("binary_tag", new BytesRef(tags[j % tags.length])));
156165
}
157166

158167
if (r % 10 == 5) {
@@ -194,6 +203,10 @@ void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersi
194203
if (tagsDV == null) {
195204
tagsDV = DocValues.emptySortedSet();
196205
}
206+
var binaryDV = MultiDocValues.getBinaryValues(reader, "binary_tag");
207+
if (binaryDV == null) {
208+
binaryDV = DocValues.emptyBinary();
209+
}
197210
for (int i = 0; i < numDocs; i++) {
198211
assertEquals(i, hostNameDV.nextDoc());
199212
String actualHostName = hostNameDV.lookupOrd(hostNameDV.ordValue()).utf8ToString();
@@ -224,6 +237,10 @@ void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersi
224237
assertTrue("unexpected tag [" + actualTag + "]", Arrays.binarySearch(tags, actualTag) >= 0);
225238
}
226239
}
240+
if (binaryDV.advanceExact(i)) {
241+
String actualBinary = binaryDV.binaryValue().utf8ToString();
242+
assertTrue("unexpected binary [" + actualBinary + "]", Arrays.binarySearch(tags, actualBinary) >= 0);
243+
}
227244
}
228245
}
229246

@@ -254,6 +271,10 @@ void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersi
254271
if (tagsDV == null) {
255272
tagsDV = DocValues.emptySortedSet();
256273
}
274+
var binaryDV = MultiDocValues.getBinaryValues(reader, "binary_tag");
275+
if (binaryDV == null) {
276+
binaryDV = DocValues.emptyBinary();
277+
}
257278
for (int i = 0; i < numDocs; i++) {
258279
assertEquals(i, hostNameDV.nextDoc());
259280
String actualHostName = hostNameDV.lookupOrd(hostNameDV.ordValue()).utf8ToString();
@@ -284,6 +305,10 @@ void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersi
284305
assertTrue("unexpected tag [" + actualTag + "]", Arrays.binarySearch(tags, actualTag) >= 0);
285306
}
286307
}
308+
if (binaryDV.advanceExact(i)) {
309+
String actualBinary = binaryDV.binaryValue().utf8ToString();
310+
assertTrue("unexpected binary [" + actualBinary + "]", Arrays.binarySearch(tags, actualBinary) >= 0);
311+
}
287312
}
288313
}
289314
}

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesConsumerVersion0.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class ES819TSDBDocValuesConsumerVersion0 extends XDocValuesConsumer {
8888
CodecUtil.writeIndexHeader(
8989
data,
9090
dataCodec,
91-
ES819TSDBDocValuesFormat.VERSION_CURRENT,
91+
ES819TSDBDocValuesFormat.VERSION_START, // Test with version 0 rather than current
9292
state.segmentInfo.getId(),
9393
state.segmentSuffix
9494
);
@@ -97,7 +97,7 @@ final class ES819TSDBDocValuesConsumerVersion0 extends XDocValuesConsumer {
9797
CodecUtil.writeIndexHeader(
9898
meta,
9999
metaCodec,
100-
ES819TSDBDocValuesFormat.VERSION_CURRENT,
100+
ES819TSDBDocValuesFormat.VERSION_START, // Test with version 0 rather than current
101101
state.segmentInfo.getId(),
102102
state.segmentSuffix
103103
);

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormatTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ protected Codec getCodec() {
117117
return codec;
118118
}
119119

120+
public void testBinaryCompressionFeatureFlag() {
121+
ES819TSDBDocValuesFormat docValueFormat = new ES819TSDBDocValuesFormat();
122+
if (ES819TSDBDocValuesFormat.BINARY_DV_COMPRESSION_FEATURE_FLAG) {
123+
assertThat(docValueFormat.binaryDVCompressionMode, equalTo(BinaryDVCompressionMode.COMPRESSED_ZSTD_LEVEL_1));
124+
} else {
125+
assertThat(docValueFormat.binaryDVCompressionMode, equalTo(BinaryDVCompressionMode.NO_COMPRESS));
126+
}
127+
}
128+
120129
// Test with data large enough to require multiple binary doc value blocks
121130
public void testBlockWiseBinarySparse() throws Exception {
122131
String timestampField = "@timestamp";

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public enum FeatureFlag {
2626
Version.fromString("9.2.0"),
2727
null
2828
),
29-
RANDOM_SAMPLING("es.random_sampling_feature_flag_enabled=true", Version.fromString("9.2.0"), null);
29+
RANDOM_SAMPLING("es.random_sampling_feature_flag_enabled=true", Version.fromString("9.2.0"), null),
30+
BINARY_DOC_VALUE_COMPRESSION("es.binary_dv_compression_feature_flag_enabled=true", Version.fromString("9.3.0"), null);
3031

3132
public final String systemProperty;
3233
public final Version from;

x-pack/plugin/logsdb/src/yamlRestTest/java/org/elasticsearch/xpack/logsdb/LogsdbTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class LogsdbTestSuiteIT extends ESClientYamlSuiteTestCase {
3737
.setting("xpack.security.autoconfiguration.enabled", "false")
3838
.setting("xpack.license.self_generated.type", "trial")
3939
.feature(FeatureFlag.DOC_VALUES_SKIPPER)
40+
.feature(FeatureFlag.BINARY_DOC_VALUE_COMPRESSION)
4041
.build();
4142

4243
public LogsdbTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

0 commit comments

Comments
 (0)