Skip to content

Commit cf552cf

Browse files
committed
Remove zstd feature flag for index codec best compression. (elastic#112665)
ZStandard was added via elastic#103374 a few months ago to snapshot builds of Elasticsearch only and benchmark results have shown that using zstd is a better trade off compared to deflate for when index.codec is set to best_compression. This change removes the feature flag for ZStandard stored field compression for indices with index.codec set to best_compression.
1 parent 12b4900 commit cf552cf

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

build-tools-internal/src/main/resources/changelog-schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"CRUD",
3333
"Client",
3434
"Cluster Coordination",
35+
"Codec",
3536
"Data streams",
3637
"DLM",
3738
"Discovery-Plugins",

docs/changelog/112665.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pr: 112665
2+
summary: Remove zstd feature flag for index codec best compression
3+
area: Codec
4+
type: enhancement
5+
issues: []
6+
highlight:
7+
title: Enable ZStandard compression for indices with index.codec set to best_compression
8+
body: |-
9+
Before DEFLATE compression was used to compress stored fields in indices with index.codec index setting set to
10+
best_compression, with this change ZStandard is used as compression algorithm to stored fields for indices with
11+
index.codec index setting set to best_compression. The usage ZStandard results in less storage usage with a
12+
similar indexing throughput depending on what options are used. Experiments with indexing logs have shown that
13+
ZStandard offers ~12% lower storage usage and a ~14% higher indexing throughput compared to DEFLATE.
14+
notable: true

docs/reference/ilm/actions/ilm-forcemerge.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Number of segments to merge to. To fully merge the index, set to `1`.
4949
`index_codec`::
5050
(Optional, string)
5151
Codec used to compress the document store. The only accepted value is
52-
`best_compression`, which uses {wikipedia}/DEFLATE[DEFLATE] for a higher
52+
`best_compression`, which uses {wikipedia}/Zstd[ZSTD] for a higher
5353
compression ratio but slower stored fields performance. To use the default LZ4
5454
codec, omit this argument.
5555
+

docs/reference/index-modules.asciidoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ breaking change].
7676

7777
The +default+ value compresses stored data with LZ4
7878
compression, but this can be set to +best_compression+
79-
which uses {wikipedia}/DEFLATE[DEFLATE] for a higher
80-
compression ratio, at the expense of slower stored fields performance.
79+
which uses {wikipedia}/Zstd[ZSTD] for a higher
80+
compression ratio, at the expense of slower stored fields read performance.
8181
If you are updating the compression type, the new one will be applied
8282
after segments are merged. Segment merging can be forced using
8383
<<indices-forcemerge,force merge>>. Experiments with indexing log datasets
84-
have shown that `best_compression` gives up to ~18% lower storage usage in
85-
the most ideal scenario compared to `default` while only minimally affecting
86-
indexing throughput (~2%).
84+
have shown that `best_compression` gives up to ~28% lower storage usage and
85+
similar indexing throughput (sometimes a bit slower or faster depending on other used options) compared
86+
to `default` while affecting get by id latencies between ~10% and ~33%. The higher get
87+
by id latencies is not a concern for many use cases like logging or metrics, since
88+
these don't really rely on get by id functionality (Get APIs or searching by _id).
8789

8890
[[index-mode-setting]] `index.mode`::
8991
+

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@ public CodecService(@Nullable MapperService mapperService, BigArrays bigArrays)
5353
}
5454
codecs.put(LEGACY_DEFAULT_CODEC, legacyBestSpeedCodec);
5555

56+
codecs.put(
57+
BEST_COMPRESSION_CODEC,
58+
new PerFieldMapperCodec(Zstd814StoredFieldsFormat.Mode.BEST_COMPRESSION, mapperService, bigArrays)
59+
);
5660
Codec legacyBestCompressionCodec = new LegacyPerFieldMapperCodec(Lucene99Codec.Mode.BEST_COMPRESSION, mapperService, bigArrays);
57-
if (ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
58-
codecs.put(
59-
BEST_COMPRESSION_CODEC,
60-
new PerFieldMapperCodec(Zstd814StoredFieldsFormat.Mode.BEST_COMPRESSION, mapperService, bigArrays)
61-
);
62-
} else {
63-
codecs.put(BEST_COMPRESSION_CODEC, legacyBestCompressionCodec);
64-
}
6561
codecs.put(LEGACY_BEST_COMPRESSION_CODEC, legacyBestCompressionCodec);
6662

6763
codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault());

server/src/test/java/org/elasticsearch/index/codec/CodecIntegrationTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
public class CodecIntegrationTests extends ESSingleNodeTestCase {
1818

1919
public void testCanConfigureLegacySettings() {
20-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
21-
2220
createIndex("index1", Settings.builder().put("index.codec", "legacy_default").build());
2321
var codec = client().admin().indices().prepareGetSettings("index1").execute().actionGet().getSetting("index1", "index.codec");
2422
assertThat(codec, equalTo("legacy_default"));
@@ -29,8 +27,6 @@ public void testCanConfigureLegacySettings() {
2927
}
3028

3129
public void testDefaultCodecLogsdb() {
32-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
33-
3430
var indexService = createIndex("index1", Settings.builder().put("index.mode", "logsdb").build());
3531
var storedFieldsFormat = (Zstd814StoredFieldsFormat) indexService.getShard(0)
3632
.getEngineOrNull()

server/src/test/java/org/elasticsearch/index/codec/CodecTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public void testDefault() throws Exception {
6464
}
6565

6666
public void testBestCompression() throws Exception {
67-
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
6867
Codec codec = createCodecService().codec("best_compression");
6968
assertEquals(
7069
"Zstd814StoredFieldsFormat(compressionMode=ZSTD(level=3), chunkSize=245760, maxDocsPerChunk=2048, blockShift=10)",

0 commit comments

Comments
 (0)