-
Couldn't load subscription status.
- Fork 9.1k
HADOOP-17125. Using snappy-java in SnappyCodec #2297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23da513
3aa3f55
65fd9f4
9c0f08b
f52dd20
87903a9
5adcf53
40cc18a
0e44d4b
666a37b
9de4712
0ed518d
712749c
2b5a212
1cb398b
aa6a6d5
19edba2
beec931
fc525fa
562b80d
0600169
fd71a20
7dc320d
5685b0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,9 @@ | |
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.compress.Compressor; | ||
| import org.apache.hadoop.util.NativeCodeLoader; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.xerial.snappy.Snappy; | ||
|
|
||
| /** | ||
| * A {@link Compressor} based on the snappy compression algorithm. | ||
|
|
@@ -48,24 +48,6 @@ public class SnappyCompressor implements Compressor { | |
| private long bytesRead = 0L; | ||
| private long bytesWritten = 0L; | ||
|
|
||
| private static boolean nativeSnappyLoaded = false; | ||
|
|
||
| static { | ||
| if (NativeCodeLoader.isNativeCodeLoaded() && | ||
| NativeCodeLoader.buildSupportsSnappy()) { | ||
| try { | ||
| initIDs(); | ||
| nativeSnappyLoaded = true; | ||
| } catch (Throwable t) { | ||
| LOG.error("failed to load SnappyCompressor", t); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static boolean isNativeCodeLoaded() { | ||
| return nativeSnappyLoaded; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to check if the snappy class is available for SnappyCompressor too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
| } | ||
|
|
||
| /** | ||
| * Creates a new compressor. | ||
| * | ||
|
|
@@ -225,7 +207,7 @@ public int compress(byte[] b, int off, int len) | |
| } | ||
|
|
||
| // Compress data | ||
| n = compressBytesDirect(); | ||
| n = compressDirectBuf(); | ||
| compressedDirectBuf.limit(n); | ||
| uncompressedDirectBuf.clear(); // snappy consumes all buffer input | ||
|
|
||
|
|
@@ -291,9 +273,16 @@ public long getBytesWritten() { | |
| public void end() { | ||
| } | ||
|
|
||
| private native static void initIDs(); | ||
|
|
||
| private native int compressBytesDirect(); | ||
|
|
||
| public native static String getLibraryName(); | ||
| private int compressDirectBuf() throws IOException { | ||
| if (uncompressedDirectBufLen == 0) { | ||
| return 0; | ||
| } else { | ||
| // Set the position and limit of `uncompressedDirectBuf` for reading | ||
| uncompressedDirectBuf.limit(uncompressedDirectBufLen).position(0); | ||
| int size = Snappy.compress((ByteBuffer) uncompressedDirectBuf, | ||
| (ByteBuffer) compressedDirectBuf); | ||
| uncompressedDirectBufLen = 0; | ||
| return size; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.