Skip to content

Commit

Permalink
introducing codecs as their algo name
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
  • Loading branch information
sarthakaggarwal97 committed Aug 4, 2023
1 parent 24595c9 commit 643f060
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public void testReindexingMultipleCodecs() throws InterruptedException, Executio
Map<String, String> codecMap = Map.of(
"best_compression",
"BEST_COMPRESSION",
"zlib",
"BEST_COMPRESSION",
"zstd_no_dict",
"ZSTD_NO_DICT",
"zstd",
"ZSTD",
"default",
"BEST_SPEED",
"lz4",
"BEST_SPEED"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public void testForceMergeMultipleCodecs() throws ExecutionException, Interrupte
Map<String, String> codecMap = Map.of(
"best_compression",
"BEST_COMPRESSION",
"zlib",
"BEST_COMPRESSION",
"zstd_no_dict",
"ZSTD_NO_DICT",
"zstd",
"ZSTD",
"default",
"BEST_SPEED",
"lz4",
"BEST_SPEED"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public class CodecService {
private final Map<String, Codec> codecs;

public static final String DEFAULT_CODEC = "default";
public static final String LZ4 = "lz4";
public static final String BEST_COMPRESSION_CODEC = "best_compression";
public static final String ZLIB = "zlib";
/**
* the raw unfiltered lucene default. useful for testing
*/
Expand All @@ -74,12 +76,16 @@ public CodecService(@Nullable MapperService mapperService, IndexSettings indexSe
int compressionLevel = indexSettings.getValue(INDEX_CODEC_COMPRESSION_LEVEL_SETTING);
if (mapperService == null) {
codecs.put(DEFAULT_CODEC, new Lucene95Codec());
codecs.put(LZ4, new Lucene95Codec());
codecs.put(BEST_COMPRESSION_CODEC, new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(ZLIB, new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(ZSTD_CODEC, new ZstdCodec(compressionLevel));
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(compressionLevel));
} else {
codecs.put(DEFAULT_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(LZ4, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
codecs.put(ZLIB, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
codecs.put(ZSTD_CODEC, new ZstdCodec(mapperService, logger, compressionLevel));
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(mapperService, logger, compressionLevel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
public static final Setting<String> INDEX_CODEC_SETTING = new Setting<>("index.codec", "default", s -> {
switch (s) {
case "default":
case "lz4":
case "best_compression":
case "zlib":
case "zstd":
case "zstd_no_dict":
case "lucene_default":
return s;
default:
if (Codec.availableCodecs().contains(s) == false) { // we don't error message the not officially supported ones
throw new IllegalArgumentException(
"unknown value for [index.codec] must be one of [default, best_compression, zstd, zstd_no_dict] but was: " + s
"unknown value for [index.codec] must be one of [default, lz4, best_compression, zlib, zstd, zstd_no_dict] but was: " + s
);
}
return s;
Expand Down Expand Up @@ -182,8 +184,10 @@ private static void doValidateCodecSettings(final String codec) {
case "zstd_no_dict":
return;
case "best_compression":
case "zlib":
case "lucene_default":
case "default":
case "lz4":
break;
default:
if (Codec.availableCodecs().contains(codec)) {
Expand Down
12 changes: 12 additions & 0 deletions server/src/test/java/org/opensearch/index/codec/CodecTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ public void testBestCompression() throws Exception {
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_COMPRESSION, codec);
}

public void testLZ4() throws Exception {
Codec codec = createCodecService(false).codec("lz4");
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_SPEED, codec);
assert codec instanceof PerFieldMappingPostingFormatCodec;
}

public void testZlib() throws Exception {
Codec codec = createCodecService(false).codec("zlib");
assertStoredFieldsCompressionEquals(Lucene95Codec.Mode.BEST_COMPRESSION, codec);
assert codec instanceof PerFieldMappingPostingFormatCodec;
}

public void testZstd() throws Exception {
Codec codec = createCodecService(false).codec("zstd");
assertStoredFieldsCompressionEquals(Lucene95CustomCodec.Mode.ZSTD, codec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
*/
public static final List<String> CODECS = List.of(
CodecService.DEFAULT_CODEC,
CodecService.LZ4,
CodecService.BEST_COMPRESSION_CODEC,
CodecService.ZLIB,
CodecService.ZSTD_CODEC,
CodecService.ZSTD_NO_DICT_CODEC
);
Expand Down

0 comments on commit 643f060

Please sign in to comment.