diff --git a/src/main/java/org/opensearch/index/codec/customcodecs/CustomCodecPlugin.java b/src/main/java/org/opensearch/index/codec/customcodecs/CustomCodecPlugin.java index ec4cda3..7015704 100644 --- a/src/main/java/org/opensearch/index/codec/customcodecs/CustomCodecPlugin.java +++ b/src/main/java/org/opensearch/index/codec/customcodecs/CustomCodecPlugin.java @@ -50,18 +50,10 @@ public Optional getCustomCodecServiceFactory(final IndexSet || codecName.equals(CustomCodecService.QAT_DEFLATE_CODEC)) { return Optional.of(new CustomCodecServiceFactory()); } else { - if (codecName.equals(Lucene99QatCodec.Mode.QAT_LZ4.getCodec()) - || codecName.equals(Lucene99QatCodec.Mode.QAT_DEFLATE.getCodec())) { - if (!QatZipperFactory.isQatAvailable()) { - throw new IllegalArgumentException("QAT codecs are not supported. Please create indices with a different codec."); - } - } - - if (codecName.equals(Lucene912QatCodec.Mode.QAT_LZ4.getCodec()) - || codecName.equals(Lucene912QatCodec.Mode.QAT_DEFLATE.getCodec())) { - if (!QatZipperFactory.isQatAvailable()) { - throw new IllegalArgumentException("QAT codecs are not supported. Please create indices with a different codec."); - } + if (!QatZipperFactory.isQatAvailable() && isQatCodec(codecName)) { + throw new IllegalArgumentException( + "QAT codecs are not supported (QAT is not available). Please create indices with a different codec." + ); } } return Optional.empty(); @@ -71,4 +63,11 @@ public Optional getCustomCodecServiceFactory(final IndexSet public List> getSettings() { return Arrays.asList(Lucene99QatCodec.INDEX_CODEC_QAT_MODE_SETTING); } + + private static boolean isQatCodec(String codecName) { + return codecName.equals(Lucene99QatCodec.Mode.QAT_LZ4.getCodec()) + || codecName.equals(Lucene99QatCodec.Mode.QAT_DEFLATE.getCodec()) + || codecName.equals(Lucene912QatCodec.Mode.QAT_LZ4.getCodec()) + || codecName.equals(Lucene912QatCodec.Mode.QAT_DEFLATE.getCodec()); + } } diff --git a/src/main/java/org/opensearch/index/codec/customcodecs/ZstdCompressionMode.java b/src/main/java/org/opensearch/index/codec/customcodecs/ZstdCompressionMode.java index 14bd7de..4fb53b7 100644 --- a/src/main/java/org/opensearch/index/codec/customcodecs/ZstdCompressionMode.java +++ b/src/main/java/org/opensearch/index/codec/customcodecs/ZstdCompressionMode.java @@ -45,7 +45,7 @@ protected ZstdCompressionMode() { * * @param compressionLevel The compression level to use. */ - public ZstdCompressionMode(int compressionLevel) { + protected ZstdCompressionMode(int compressionLevel) { this.compressionLevel = compressionLevel; } diff --git a/src/main/java/org/opensearch/index/codec/customcodecs/ZstdNoDictCompressionMode.java b/src/main/java/org/opensearch/index/codec/customcodecs/ZstdNoDictCompressionMode.java index c918355..fdee56d 100644 --- a/src/main/java/org/opensearch/index/codec/customcodecs/ZstdNoDictCompressionMode.java +++ b/src/main/java/org/opensearch/index/codec/customcodecs/ZstdNoDictCompressionMode.java @@ -40,7 +40,7 @@ protected ZstdNoDictCompressionMode() { * * @param compressionLevel The compression level. */ - public ZstdNoDictCompressionMode(int compressionLevel) { + protected ZstdNoDictCompressionMode(int compressionLevel) { this.compressionLevel = compressionLevel; } diff --git a/src/main/java/org/opensearch/index/codec/customcodecs/backward_codecs/lucene99/Lucene99CustomStoredFieldsFormat.java b/src/main/java/org/opensearch/index/codec/customcodecs/backward_codecs/lucene99/Lucene99CustomStoredFieldsFormat.java index d988ca1..637f454 100644 --- a/src/main/java/org/opensearch/index/codec/customcodecs/backward_codecs/lucene99/Lucene99CustomStoredFieldsFormat.java +++ b/src/main/java/org/opensearch/index/codec/customcodecs/backward_codecs/lucene99/Lucene99CustomStoredFieldsFormat.java @@ -62,8 +62,10 @@ public Lucene99CustomStoredFieldsFormat(Lucene99CustomCodec.Mode mode) { public Lucene99CustomStoredFieldsFormat(Lucene99CustomCodec.Mode mode, int compressionLevel) { this.mode = Objects.requireNonNull(mode); this.compressionLevel = compressionLevel; - zstdCompressionMode = new ZstdCompressionMode(compressionLevel); - zstdNoDictCompressionMode = new ZstdNoDictCompressionMode(compressionLevel); + zstdCompressionMode = new ZstdCompressionMode(compressionLevel) { + }; + zstdNoDictCompressionMode = new ZstdNoDictCompressionMode(compressionLevel) { + }; } /** diff --git a/src/test/java/org/opensearch/index/codec/customcodecs/backward_codecs/Lucene95CustomStoredFieldsFormatTests.java b/src/test/java/org/opensearch/index/codec/customcodecs/backward_codecs/Lucene95CustomStoredFieldsFormatTests.java index 4643246..7cd78d5 100644 --- a/src/test/java/org/opensearch/index/codec/customcodecs/backward_codecs/Lucene95CustomStoredFieldsFormatTests.java +++ b/src/test/java/org/opensearch/index/codec/customcodecs/backward_codecs/Lucene95CustomStoredFieldsFormatTests.java @@ -6,10 +6,10 @@ * compatible open source license. */ -package org.opensearch.index.codec.customcodecs; +package org.opensearch.index.codec.customcodecs.backward_codecs; -import org.opensearch.index.codec.customcodecs.backward_codecs.Lucene95CustomCodec; -import org.opensearch.index.codec.customcodecs.backward_codecs.Lucene95CustomStoredFieldsFormat; +import org.opensearch.index.codec.customcodecs.ZstdCompressionMode; +import org.opensearch.index.codec.customcodecs.ZstdNoDictCompressionMode; import org.opensearch.test.OpenSearchTestCase; public class Lucene95CustomStoredFieldsFormatTests extends OpenSearchTestCase {