Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Oct 16, 2024
1 parent ef154c8 commit f1e06f7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Lucene912QatStoredFieldsFormat(Lucene912QatCodec.Mode mode, Supplier<QatZ
*/
public Lucene912QatStoredFieldsFormat(Lucene912QatCodec.Mode mode, int compressionLevel, Supplier<QatZipper.Mode> supplier) {
this.mode = Objects.requireNonNull(mode);
qatCompressionMode = new QatCompressionMode(mode, compressionLevel, supplier);
qatCompressionMode = new QatCompressionMode(getAlgorithm(mode), compressionLevel, supplier);
}

/**
Expand Down Expand Up @@ -176,4 +176,13 @@ public Lucene912QatCodec.Mode getMode() {
public QatCompressionMode getCompressionMode() {
return qatCompressionMode;
}

/**
* Returns {@link QatZipper.Algorithm} instance that corresponds codec's {@link Lucene912QatCodec.Mode mode}
* @param mode codec's {@link Lucene912QatCodec.Mode mode}
* @return the {@link QatZipper.Algorithm} instance that corresponds codec's {@link Lucene912QatCodec.Mode mode}
*/
private static QatZipper.Algorithm getAlgorithm(Lucene912QatCodec.Mode mode) {
return (mode == Lucene912QatCodec.Mode.QAT_LZ4) ? QatZipper.Algorithm.LZ4 : QatZipper.Algorithm.DEFLATE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public class QatCompressionMode extends CompressionMode {

/** default constructor */
protected QatCompressionMode() {
this(Lucene912QatCodec.DEFAULT_COMPRESSION_MODE, DEFAULT_COMPRESSION_LEVEL, () -> { return DEFAULT_QAT_MODE; });
this(QatZipper.Algorithm.LZ4, DEFAULT_COMPRESSION_LEVEL, () -> { return DEFAULT_QAT_MODE; });
}

/**
* Creates a new instance.
*
* @param mode The compression mode (QAT_LZ4 or QAT_DEFLATE)
*/
protected QatCompressionMode(Lucene912QatCodec.Mode mode) {
this(mode, DEFAULT_COMPRESSION_LEVEL, () -> { return DEFAULT_QAT_MODE; });
protected QatCompressionMode(QatZipper.Algorithm algorithm) {
this(algorithm, DEFAULT_COMPRESSION_LEVEL, () -> { return DEFAULT_QAT_MODE; });
}

/**
Expand All @@ -54,8 +54,8 @@ protected QatCompressionMode(Lucene912QatCodec.Mode mode) {
* @param mode The compression mode (QAT_LZ4 or QAT_DEFLATE)
* @param compressionLevel The compression level to use.
*/
protected QatCompressionMode(Lucene912QatCodec.Mode mode, int compressionLevel) {
this(mode, compressionLevel, () -> { return DEFAULT_QAT_MODE; });
protected QatCompressionMode(QatZipper.Algorithm algorithm, int compressionLevel) {
this(algorithm, compressionLevel, () -> { return DEFAULT_QAT_MODE; });
}

/**
Expand All @@ -65,8 +65,8 @@ protected QatCompressionMode(Lucene912QatCodec.Mode mode, int compressionLevel)
* @param compressionLevel The compression level to use.
* @param supplier a supplier for QAT acceleration mode.
*/
protected QatCompressionMode(Lucene912QatCodec.Mode mode, int compressionLevel, Supplier<QatZipper.Mode> supplier) {
this.algorithm = mode == Lucene912QatCodec.Mode.QAT_LZ4 ? QatZipper.Algorithm.LZ4 : QatZipper.Algorithm.DEFLATE;
protected QatCompressionMode(QatZipper.Algorithm algorithm, int compressionLevel, Supplier<QatZipper.Mode> supplier) {
this.algorithm = algorithm;
this.compressionLevel = compressionLevel;
this.supplier = supplier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.opensearch.index.codec.customcodecs.QatCompressionMode;

import java.io.IOException;
import java.util.Objects;
Expand Down Expand Up @@ -84,7 +85,8 @@ public Lucene99QatStoredFieldsFormat(Lucene99QatCodec.Mode mode, Supplier<QatZip
*/
public Lucene99QatStoredFieldsFormat(Lucene99QatCodec.Mode mode, int compressionLevel, Supplier<QatZipper.Mode> supplier) {
this.mode = Objects.requireNonNull(mode);
qatCompressionMode = new QatCompressionMode(mode, compressionLevel, supplier);
qatCompressionMode = new QatCompressionMode(getAlgorithm(mode), compressionLevel, supplier) {
};
}

/**
Expand Down Expand Up @@ -173,4 +175,13 @@ public Lucene99QatCodec.Mode getMode() {
public QatCompressionMode getCompressionMode() {
return qatCompressionMode;
}

/**
* Returns {@link QatZipper.Algorithm} instance that corresponds codec's {@link Lucene99QatCodec.Mode mode}
* @param mode codec's {@link Lucene99QatCodec.Mode mode}
* @return the {@link QatZipper.Algorithm} instance that corresponds codec's {@link Lucene99QatCodec.Mode mode}
*/
private static QatZipper.Algorithm getAlgorithm(Lucene99QatCodec.Mode mode) {
return (mode == Lucene99QatCodec.Mode.QAT_LZ4) ? QatZipper.Algorithm.LZ4 : QatZipper.Algorithm.DEFLATE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.lucene.codecs.compressing.Compressor;
import org.apache.lucene.codecs.compressing.Decompressor;

import com.intel.qat.QatZipper;

import java.io.IOException;

import static org.hamcrest.Matchers.is;
Expand All @@ -21,13 +23,13 @@ public class QatDeflateCompressorTests extends AbstractCompressorTests {
@Override
Compressor compressor() {
assumeThat("Qat library is available", QatZipperFactory.isQatAvailable(), is(true));
return new QatCompressionMode(Lucene912QatCodec.Mode.QAT_DEFLATE).newCompressor();
return new QatCompressionMode(QatZipper.Algorithm.DEFLATE).newCompressor();
}

@Override
Decompressor decompressor() {
assumeThat("Qat library is available", QatZipperFactory.isQatAvailable(), is(true));
return new QatCompressionMode(Lucene912QatCodec.Mode.QAT_DEFLATE).newDecompressor();
return new QatCompressionMode(QatZipper.Algorithm.DEFLATE).newDecompressor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.lucene.codecs.compressing.Compressor;
import org.apache.lucene.codecs.compressing.Decompressor;

import com.intel.qat.QatZipper;

import java.io.IOException;

import static org.hamcrest.Matchers.is;
Expand All @@ -21,13 +23,13 @@ public class QatLz4CompressorTests extends AbstractCompressorTests {
@Override
Compressor compressor() {
assumeThat("Qat library is available", QatZipperFactory.isQatAvailable(), is(true));
return new QatCompressionMode(Lucene912QatCodec.Mode.QAT_LZ4).newCompressor();
return new QatCompressionMode(QatZipper.Algorithm.LZ4).newCompressor();
}

@Override
Decompressor decompressor() {
assumeThat("Qat library is available", QatZipperFactory.isQatAvailable(), is(true));
return new QatCompressionMode(Lucene912QatCodec.Mode.QAT_LZ4).newDecompressor();
return new QatCompressionMode(QatZipper.Algorithm.LZ4).newDecompressor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.index.codec.customcodecs.backward_codecs.lucene99;

import org.opensearch.index.codec.customcodecs.QatCompressionMode;
import org.opensearch.index.codec.customcodecs.QatZipperFactory;
import org.opensearch.test.OpenSearchTestCase;

Expand Down

0 comments on commit f1e06f7

Please sign in to comment.