Skip to content

Commit 32e8187

Browse files
introducing codecs as their algo name (opensearch-project#9123) (opensearch-project#9170)
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> (cherry picked from commit 3713bcb)
1 parent e752bc3 commit 32e8187

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212
- Disallow compression level to be set for default and best_compression index codecs ([#8737]()https://github.com/opensearch-project/OpenSearch/pull/8737)
1313
- [distribution/archives] [Linux] [x64] Provide the variant of the distributions bundled with JRE ([#8195]()https://github.com/opensearch-project/OpenSearch/pull/8195)
1414
- Prioritize replica shard movement during shard relocation ([#8875](https://github.com/opensearch-project/OpenSearch/pull/8875))
15+
- Introducing Default and Best Compression codecs as their algorithm name ([#9123]()https://github.com/opensearch-project/OpenSearch/pull/9123)
1516

1617
### Dependencies
1718
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))

modules/reindex/src/internalClusterTest/java/org/opensearch/index/codec/MultiCodecReindexIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ public void testReindexingMultipleCodecs() throws InterruptedException, Executio
4545
Map<String, String> codecMap = Map.of(
4646
"best_compression",
4747
"BEST_COMPRESSION",
48+
"zlib",
49+
"BEST_COMPRESSION",
4850
"zstd_no_dict",
4951
"ZSTD_NO_DICT",
5052
"zstd",
5153
"ZSTD",
5254
"default",
55+
"BEST_SPEED",
56+
"lz4",
5357
"BEST_SPEED"
5458
);
5559

server/src/internalClusterTest/java/org/opensearch/index/codec/MultiCodecMergeIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ public void testForceMergeMultipleCodecs() throws ExecutionException, Interrupte
4545
Map<String, String> codecMap = Map.of(
4646
"best_compression",
4747
"BEST_COMPRESSION",
48+
"zlib",
49+
"BEST_COMPRESSION",
4850
"zstd_no_dict",
4951
"ZSTD_NO_DICT",
5052
"zstd",
5153
"ZSTD",
5254
"default",
55+
"BEST_SPEED",
56+
"lz4",
5357
"BEST_SPEED"
5458
);
5559

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public class CodecService {
6161
private final Map<String, Codec> codecs;
6262

6363
public static final String DEFAULT_CODEC = "default";
64+
public static final String LZ4 = "lz4";
6465
public static final String BEST_COMPRESSION_CODEC = "best_compression";
66+
public static final String ZLIB = "zlib";
6567
/**
6668
* the raw unfiltered lucene default. useful for testing
6769
*/
@@ -75,12 +77,16 @@ public CodecService(@Nullable MapperService mapperService, IndexSettings indexSe
7577
int compressionLevel = indexSettings.getValue(INDEX_CODEC_COMPRESSION_LEVEL_SETTING);
7678
if (mapperService == null) {
7779
codecs.put(DEFAULT_CODEC, new Lucene95Codec());
80+
codecs.put(LZ4, new Lucene95Codec());
7881
codecs.put(BEST_COMPRESSION_CODEC, new Lucene95Codec(Mode.BEST_COMPRESSION));
82+
codecs.put(ZLIB, new Lucene95Codec(Mode.BEST_COMPRESSION));
7983
codecs.put(ZSTD_CODEC, new ZstdCodec(compressionLevel));
8084
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(compressionLevel));
8185
} else {
8286
codecs.put(DEFAULT_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
87+
codecs.put(LZ4, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
8388
codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
89+
codecs.put(ZLIB, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
8490
codecs.put(ZSTD_CODEC, new ZstdCodec(mapperService, logger, compressionLevel));
8591
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(mapperService, logger, compressionLevel));
8692
}

server/src/main/java/org/opensearch/index/engine/EngineConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,18 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
130130
public static final Setting<String> INDEX_CODEC_SETTING = new Setting<>("index.codec", "default", s -> {
131131
switch (s) {
132132
case "default":
133+
case "lz4":
133134
case "best_compression":
135+
case "zlib":
134136
case "zstd":
135137
case "zstd_no_dict":
136138
case "lucene_default":
137139
return s;
138140
default:
139141
if (Codec.availableCodecs().contains(s) == false) { // we don't error message the not officially supported ones
140142
throw new IllegalArgumentException(
141-
"unknown value for [index.codec] must be one of [default, best_compression, zstd, zstd_no_dict] but was: " + s
143+
"unknown value for [index.codec] must be one of [default, lz4, best_compression, zlib, zstd, zstd_no_dict] but was: "
144+
+ s
142145
);
143146
}
144147
return s;
@@ -182,8 +185,10 @@ private static void doValidateCodecSettings(final String codec) {
182185
case "zstd_no_dict":
183186
return;
184187
case "best_compression":
188+
case "zlib":
185189
case "lucene_default":
186190
case "default":
191+
case "lz4":
187192
break;
188193
default:
189194
if (Codec.availableCodecs().contains(codec)) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public void testBestCompression() throws Exception {
8383
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_COMPRESSION, codec);
8484
}
8585

86+
public void testLZ4() throws Exception {
87+
Codec codec = createCodecService(false).codec("lz4");
88+
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_SPEED, codec);
89+
assert codec instanceof PerFieldMappingPostingFormatCodec;
90+
}
91+
92+
public void testZlib() throws Exception {
93+
Codec codec = createCodecService(false).codec("zlib");
94+
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_COMPRESSION, codec);
95+
assert codec instanceof PerFieldMappingPostingFormatCodec;
96+
}
97+
8698
public void testZstd() throws Exception {
8799
Codec codec = createCodecService(false).codec("zstd");
88100
assertStoredFieldsCompressionEquals(Lucene95CustomCodec.Mode.ZSTD, codec);

test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,11 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
379379
* The lucene_default {@link Codec} is not added to the list as it internally maps to Asserting {@link Codec}.
380380
* The override to fetch the {@link CompletionFieldMapper.CompletionFieldType} postings format is not available for this codec.
381381
*/
382-
public static List<String> CODECS = List.of(
382+
public static final List<String> CODECS = List.of(
383383
CodecService.DEFAULT_CODEC,
384+
CodecService.LZ4,
384385
CodecService.BEST_COMPRESSION_CODEC,
386+
CodecService.ZLIB,
385387
CodecService.ZSTD_CODEC,
386388
CodecService.ZSTD_NO_DICT_CODEC
387389
);

0 commit comments

Comments
 (0)