Skip to content

Commit

Permalink
Add logging for LZ4Factory instance type (#8341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-wei authored Aug 20, 2019
1 parent 5e35500 commit e2a25fb
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.druid.java.util.common.ByteBufferUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.io.Closer;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.segment.CompressedPools;

import java.io.IOException;
Expand Down Expand Up @@ -105,6 +106,8 @@ public Compressor getCompressor()
throw new UnsupportedOperationException("NONE compression strategy shouldn't use any compressor");
}
};
private static final Logger LOG = new Logger(CompressionStrategy.class);

public static final CompressionStrategy DEFAULT_COMPRESSION_STRATEGY = LZ4;

final byte id;
Expand Down Expand Up @@ -309,6 +312,10 @@ public static class LZ4Compressor extends Compressor
private static final LZ4Compressor defaultCompressor = new LZ4Compressor();
private static final net.jpountz.lz4.LZ4Compressor lz4High = LZ4Factory.fastestInstance().highCompressor();

static {
logLZ4State();
}

@Override
ByteBuffer allocateInBuffer(int inputSize, Closer closer)
{
Expand Down Expand Up @@ -336,4 +343,36 @@ public ByteBuffer compress(ByteBuffer in, ByteBuffer out)
return out;
}
}

/**
* Logs info relating to whether LZ4 is using native or pure Java implementations
*/
private static void logLZ4State()
{
LOG.info("java.library.path: " + System.getProperty("java.library.path"));
LZ4Factory fastestInstance = LZ4Factory.fastestInstance();
try {
//noinspection ObjectEquality
if (fastestInstance == LZ4Factory.nativeInstance()) {
LOG.info("LZ4 compression is using native instance.");
}
}
catch (Throwable t) {
// getting an exception means we're not using the native instance
}
try {
//noinspection ObjectEquality
if (fastestInstance == LZ4Factory.unsafeInstance()) {
LOG.info("LZ4 compression is using unsafe instance.");
}
}
catch (Throwable t) {
// getting an exception means we're not using the unsafe instance
}

//noinspection ObjectEquality
if (fastestInstance == LZ4Factory.safeInstance()) {
LOG.info("LZ4 compression is using safe instance.");
}
}
}

0 comments on commit e2a25fb

Please sign in to comment.