From c21a82a6978c742392bdf11b6bebfb14f1c085a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Tue, 2 Dec 2014 23:49:34 -0800 Subject: [PATCH] upgrade LZ4 to operate directly on ByteBuffers --- pom.xml | 2 +- .../data/CompressedObjectStrategy.java | 37 ++++--------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 660e18cda0d..7434fd6e0a7 100644 --- a/pom.xml +++ b/pom.xml @@ -383,7 +383,7 @@ net.jpountz.lz4 lz4 - 1.2.0 + 1.3.0 com.google.protobuf diff --git a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java index feea7d8abbf..b646fd800c2 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java @@ -19,9 +19,7 @@ package io.druid.segment.data; -import com.google.common.base.Throwables; import com.google.common.collect.Maps; -import com.metamx.common.guava.CloseQuietly; import com.metamx.common.logger.Logger; import com.ning.compress.lzf.ChunkEncoder; import com.ning.compress.lzf.LZFChunk; @@ -34,7 +32,6 @@ import net.jpountz.lz4.LZ4SafeDecompressor; import java.io.IOException; import java.nio.Buffer; -import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Map; @@ -233,38 +230,18 @@ public class CompressedObjectStrategy implements ObjectStrateg @Override public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) { - final byte[] bytes = new byte[numBytes]; - in.get(bytes); - - try (final ResourceHolder outputBytesHolder = CompressedPools.getOutputBytes()) { - final byte[] outputBytes = outputBytesHolder.get(); - // Since decompressed size is NOT known, must use lz4Safe - final int numDecompressedBytes = lz4Safe.decompress(bytes, outputBytes); - out.put(outputBytes, 0, numDecompressedBytes); - out.flip(); - } - catch (IOException e) { - log.error(e, "IOException thrown while closing ChunkEncoder."); - } + // Since decompressed size is NOT known, must use lz4Safe + // lz4Safe.decompress does not modify buffer positions + final int numDecompressedBytes = lz4Safe.decompress(in, in.position(), numBytes, out, out.position(), out.remaining()); + out.limit(out.position() + numDecompressedBytes); } @Override public void decompress(ByteBuffer in, int numBytes, ByteBuffer out, int decompressedSize) { - final byte[] bytes = new byte[numBytes]; - in.get(bytes); - - // TODO: Upgrade this to ByteBuffer once https://github.com/jpountz/lz4-java/issues/9 is in mainline code for lz4-java - try (final ResourceHolder outputBytesHolder = CompressedPools.getOutputBytes()) { - final byte[] outputBytes = outputBytesHolder.get(); - lz4Fast.decompress(bytes, 0, outputBytes, 0, decompressedSize); - - out.put(outputBytes, 0, decompressedSize); - out.flip(); - } - catch (IOException e) { - log.error(e, "IOException thrown while closing ChunkEncoder."); - } + // lz4Fast.decompress does not modify buffer positions + lz4Fast.decompress(in, in.position(), out, out.position(), decompressedSize); + out.limit(out.position() + decompressedSize); } }