Skip to content

Commit

Permalink
incorporating review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
  • Loading branch information
sarthakaggarwal97 committed Sep 5, 2023
1 parent 7b1179f commit b9e4fa1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.opensearch.index.codec.PerFieldMappingPostingFormatCodec;
import org.opensearch.index.mapper.MapperService;

import java.util.Collections;
import java.util.Set;

/**
*
* Extends {@link FilterCodec} to reuse the functionality of Lucene Codec.
Expand All @@ -32,20 +35,24 @@ public enum Mode {
/**
* ZStandard mode with dictionary
*/
ZSTD("ZSTD"),
ZSTD("ZSTD", Set.of("zstd")),
/**
* ZStandard mode without dictionary
*/
ZSTD_NO_DICT("ZSTDNODICT"),
ZSTD_NO_DICT("ZSTDNODICT", Set.of("zstd_no_dict")),
/**
* Default ZStandard mode
* Deprecated ZStandard mode, added for backward compatibility to support indices created in 2.9.0 where
* both ZSTD and ZSTD_NO_DICT used Lucene95CustomCodec underneath. This should not be used to
* create new indices.
*/
ZSTD_DEPRECATED("Lucene95CustomCodec");
ZSTD_DEPRECATED("Lucene95CustomCodec", Collections.emptySet());

private final String codec;
private final Set<String> aliases;

Mode(String codec) {
Mode(String codec, Set<String> aliases) {
this.codec = codec;
this.aliases = aliases;
}

/**
Expand All @@ -54,6 +61,13 @@ public enum Mode {
public String getCodec() {
return codec;
}

/**
* Returns the aliases of the Codec
*/
public Set<String> getAliases() {
return aliases;
}
}

private final StoredFieldsFormat storedFieldsFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public boolean supports(Setting<?> setting) {

@Override
public Set<String> aliases() {
return Set.of("zstd");
return Mode.ZSTD.getAliases();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@

import org.apache.logging.log4j.Logger;
import org.opensearch.common.settings.Setting;
import org.opensearch.index.codec.CodecAliases;
import org.opensearch.index.codec.CodecSettings;
import org.opensearch.index.engine.EngineConfig;
import org.opensearch.index.mapper.MapperService;

import java.util.Set;

/**
* ZstdDefaultCodec provides ZSTD compressor using the <a href="https://github.com/luben/zstd-jni">zstd-jni</a> library.
* ZstdDeprecatedCodec provides ZSTD compressor using the <a href="https://github.com/luben/zstd-jni">zstd-jni</a> library.
* Added to support backward compatibility for indices created with Lucene95CustomCodec as codec name.
*/
@Deprecated(since = "2.10")
public class ZstdDeprecatedCodec extends Lucene95CustomCodec implements CodecSettings, CodecAliases {
public class ZstdDeprecatedCodec extends Lucene95CustomCodec implements CodecSettings {

/**
* Creates a new ZstdDefaultCodec instance with the default compression level.
Expand Down Expand Up @@ -60,9 +58,4 @@ public String toString() {
public boolean supports(Setting<?> setting) {
return setting.equals(EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING);
}

@Override
public Set<String> aliases() {
return Set.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public boolean supports(Setting<?> setting) {

@Override
public Set<String> aliases() {
return Set.of("zstd_no_dict");
return Mode.ZSTD_NO_DICT.getAliases();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public void testZstdNoDict() throws Exception {
assertEquals(Lucene95CustomCodec.DEFAULT_COMPRESSION_LEVEL, storedFieldsFormat.getCompressionLevel());
}

public void testZstdDeprecatedCodec() {
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> createCodecService(false).codec("ZSTD_DEPRECATED")
);
assertTrue(e.getMessage().startsWith("failed to find codec"));
}

public void testZstdWithCompressionLevel() throws Exception {
int randomCompressionLevel = randomIntBetween(1, 6);
Codec codec = createCodecService(randomCompressionLevel, "zstd").codec("zstd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public interface CodecAliases {
*
* @return A non-null set of alias strings. If no aliases are available, an empty set should be returned.
*/
Set<String> aliases();
default Set<String> aliases() {
return Set.of();
}
}

0 comments on commit b9e4fa1

Please sign in to comment.