Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ opensearchplugin {

dependencies {
api "com.github.luben:zstd-jni:1.5.6-1"
api "com.intel.qat:qat-java:2.4.0"
api "com.intel.qat:qat-java:2.5.0"
}

allprojects {
Expand Down
1 change: 0 additions & 1 deletion licenses/qat-java-2.4.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions licenses/qat-java-2.5.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b1adc9a53eb6f1e8d61407f3461406d546bd11d4
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,41 @@ public void decompress(DataInput in, int originalLength, int offset, int length,
offsetInBytesRef -= blockLength;
}

// Read blocks that intersect with the interval we need
// Read all needed sub-blocks into a packed compressed buffer.
// Start from a modest estimate (compressed data is typically smaller
// than the decompressed size) and grow on demand while packing.
compressed = ArrayUtil.growNoCopy(compressed, originalLength / 2);
int srcPos = 0;
int totalDecompressed = 0;

while (offsetInBlock < offset + length) {
final int compressedLength = in.readVInt();
if (compressedLength == 0) {
return;
break;
}
compressed = ArrayUtil.growNoCopy(compressed, compressedLength);
in.readBytes(compressed, 0, compressedLength);

int l = Math.min(blockLength, originalLength - offsetInBlock);
bytes.bytes = ArrayUtil.grow(bytes.bytes, bytes.length + l);

final int uncompressed = qatZipper.decompress(compressed, 0, compressedLength, bytes.bytes, bytes.length, l);

bytes.length += uncompressed;
compressed = ArrayUtil.grow(compressed, srcPos + compressedLength);
in.readBytes(compressed, srcPos, compressedLength);
srcPos += compressedLength;
totalDecompressed += Math.min(blockLength, originalLength - offsetInBlock);
offsetInBlock += blockLength;
}

if (srcPos == 0) {
return;
}

bytes.bytes = ArrayUtil.grow(bytes.bytes, totalDecompressed);

// Single JNI call: native side loops through all concatenated
// compressed frames, decompressing them into the output buffer.
int totalWritten = qatZipper.decompressFull(compressed, 0, srcPos, bytes.bytes, 0, totalDecompressed);
assert totalWritten == totalDecompressed : "Decompressed byte count ("
+ totalWritten
+ ") does not match expected ("
+ totalDecompressed
+ ").";

bytes.offset = offsetInBytesRef;
bytes.length = length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index.codec.customcodecs;

import com.intel.qat.QatZipper;
Expand All @@ -15,174 +14,133 @@
import static com.intel.qat.QatZipper.DEFAULT_COMPRESSION_LEVEL_ZSTD;
import static com.intel.qat.QatZipper.DEFAULT_MODE;
import static com.intel.qat.QatZipper.DEFAULT_POLLING_MODE;
import static com.intel.qat.QatZipper.DEFAULT_RETRY_COUNT;
import static com.intel.qat.QatZipper.Mode;
import static com.intel.qat.QatZipper.PollingMode;

/** A factory class to create instances of QatZipper */
public class QatZipperFactory {

/**
* Creates a new QatZipper with the specified parameters.
*
* @param algorithm the compression algorithm
* @param level the compression level.
* @param mode the mode of QAT execution
* @param retryCount the number of attempts to acquire hardware resources
* @param pmode polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, int level, Mode mode, int retryCount, PollingMode pmode) {
return new QatZipper.Builder().algorithm(algorithm).level(level).mode(mode).retryCount(retryCount).pollingMode(pmode).build();
public static QatZipper createInstance(Algorithm algorithm, int level, Mode mode, PollingMode pmode) {
return new QatZipper.Builder().algorithm(algorithm).level(level).mode(mode).pollingMode(pmode).build();
}

/**
* Creates a new QatZipper with the specified parameters. The default compression level for the algorithm is used.
*
* @param algorithm the compression algorithm
* @param mode the mode of QAT execution
* @param retryCount the number of attempts to acquire hardware resources
* @param pmode polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, Mode mode, int retryCount, PollingMode pmode) {
public static QatZipper createInstance(Algorithm algorithm, Mode mode, PollingMode pmode) {
return createInstance(
algorithm,
algorithm == Algorithm.ZSTD ? DEFAULT_COMPRESSION_LEVEL_ZSTD : DEFAULT_COMPRESSION_LEVEL_DEFLATE,
mode,
retryCount,
pmode
);
}

/**
* Creates a new QatZipper that uses the DEFLATE algorithm and the default compression level,
* mode, retry count, and polling mode.
* mode, and polling mode.
*/
public static QatZipper createInstance() {
return createInstance(Algorithm.DEFLATE, DEFAULT_MODE, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(Algorithm.DEFLATE, DEFAULT_MODE, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified compression algorithm. Uses the default compression
* level, mode, retry count, and polling mode.
* level, mode, and polling mode.
*
* @param algorithm the compression algorithm
*/
public static QatZipper createInstance(Algorithm algorithm) {
return createInstance(algorithm, DEFAULT_MODE, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(algorithm, DEFAULT_MODE, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified execution mode. Uses the DEFLATE algorithm with the
* default compression level, retry count, and polling mode.
* default compression level and polling mode.
*
* @param mode the mode of QAT execution
*/
public static QatZipper createInstance(Mode mode) {
return createInstance(Algorithm.DEFLATE, mode, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(Algorithm.DEFLATE, mode, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified polling polling mode. Uses the DEFLATE algorithm
* with the default compression level, mode, and retry count.
* with the default compression level and mode.
*
* @param pmode the polling mode.
*/
public static QatZipper createInstance(PollingMode pmode) {
return createInstance(Algorithm.DEFLATE, DEFAULT_MODE, DEFAULT_RETRY_COUNT, pmode);
return createInstance(Algorithm.DEFLATE, DEFAULT_MODE, pmode);
}

/**
* Creates a new QatZipper with the specified algorithm and compression level. Uses the default
* mode, retry count, and polling mode.
* mode and polling mode.
*
* @param algorithm the compression algorithm (DEFLATE, LZ4, or ZSTD).
* @param level the compression level.
*/
public static QatZipper createInstance(Algorithm algorithm, int level) {
return createInstance(algorithm, level, DEFAULT_MODE, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(algorithm, level, DEFAULT_MODE, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified algorithm and mode of execution. Uses the default
* compression level, retry count, and polling mode.
* compression level and polling mode.
*
* @param algorithm the compression algorithm
* @param mode the mode of QAT execution
*/
public static QatZipper createInstance(Algorithm algorithm, Mode mode) {
return createInstance(algorithm, mode, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(algorithm, mode, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified algorithm and polling mode of execution. Uses the
* default compression level, mode, and retry count.
* default compression level and mode.
*
* @param algorithm the compression algorithm
* @param pmode the polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, PollingMode pmode) {
return createInstance(algorithm, DEFAULT_MODE, DEFAULT_RETRY_COUNT, pmode);
}

/**
* Creates a new QatZipper with the specified algorithm and mode of execution. Uses compression
* level and retry count.
*
* @param algorithm the compression algorithm
* @param mode the mode of QAT execution
* @param pmode the polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, Mode mode, PollingMode pmode) {
return createInstance(algorithm, mode, DEFAULT_RETRY_COUNT, pmode);
return createInstance(algorithm, DEFAULT_MODE, pmode);
}

/**
* Creates a new QatZipper with the specified algorithm, compression level, and mode . Uses the
* default retry count and polling mode.
* Creates a new QatZipper with the specified algorithm, compression level, and mode. Uses the
* default polling mode.
*
* @param algorithm the compression algorithm (DEFLATE, LZ4, or ZSTD).
* @param level the compression level.
* @param mode the mode of operation (HARDWARE - only hardware, AUTO - hardware with a software
* failover.)
*/
public static QatZipper createInstance(Algorithm algorithm, int level, Mode mode) {
return createInstance(algorithm, level, mode, DEFAULT_RETRY_COUNT, DEFAULT_POLLING_MODE);
return createInstance(algorithm, level, mode, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified algorithm, compression level, and polling mode .
* Uses the default mode and retry count.
* Creates a new QatZipper with the specified algorithm, compression level, and polling mode.
* Uses the default mode.
*
* @param algorithm the compression algorithm (DEFLATE, LZ4, or ZSTD).
* @param level the compression level.
* @param pmode the polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, int level, PollingMode pmode) {
return createInstance(algorithm, level, DEFAULT_MODE, DEFAULT_RETRY_COUNT, pmode);
}

/**
* Creates a new QatZipper with the specified parameters and polling mode.
*
* @param algorithm the compression algorithm
* @param level the compression level.
* @param mode the mode of QAT execution
* @param retryCount the number of attempts to acquire hardware resources
*/
public static QatZipper createInstance(Algorithm algorithm, int level, Mode mode, int retryCount) {
return createInstance(algorithm, level, mode, retryCount, DEFAULT_POLLING_MODE);
}

/**
* Creates a new QatZipper with the specified parameters and retry count.
*
* @param algorithm the compression algorithm
* @param level the compression level.
* @param mode the mode of QAT execution
* @param pmode the polling mode.
*/
public static QatZipper createInstance(Algorithm algorithm, int level, Mode mode, PollingMode pmode) {
return createInstance(algorithm, level, mode, DEFAULT_RETRY_COUNT, pmode);
return createInstance(algorithm, level, DEFAULT_MODE, pmode);
}

/**
Expand All @@ -199,7 +157,6 @@ public static boolean isQatAvailable() {
*/
private static class QatAvailableHolder {
static final boolean IS_QAT_AVAILABLE;

static {
boolean isQatAvailable;
try {
Expand Down
Loading