You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by "advancedxy (via GitHub)" <gi...@apache.org> on 2023/04/19 15:36:27 UTC
[GitHub] [incubator-uniffle] advancedxy commented on a diff in pull request #830: [#593][part-1]feat:Codec compress support ByteBuffer
advancedxy commented on code in PR #830:
URL: https://github.com/apache/incubator-uniffle/pull/830#discussion_r1171519536
##########
common/src/main/java/org/apache/uniffle/common/compression/SnappyCodec.java:
##########
@@ -64,4 +64,20 @@ public byte[] compress(byte[] src) {
throw new RssException("Failed to uncompress by Snappy", e);
}
}
+
+ @Override
+ public int compress(ByteBuffer src, ByteBuffer dest) {
+ try {
+ int compressedSize = Snappy.compress(src.duplicate(), dest);
Review Comment:
this is wrong, snappy doesn't support heap ByteBuffer. It requires that src and dest are both direct byte buffer.
You should check how decompress works, and change it accordingly.
##########
common/src/main/java/org/apache/uniffle/common/compression/Codec.java:
##########
@@ -55,6 +55,20 @@ public static Codec newInstance(RssConf rssConf) {
*/
public abstract byte[] compress(byte[] src);
+ /**
+ * Compresses the data in buffer src into dest.
+ * dest ByteBuffer.remaining() must be exactly the size of the decompressed data.
Review Comment:
> dest ByteBuffer.remaining() must be exactly the size of the decompressed data
This is too restrictive and a bit wrong. Normally it requires that the dest buffer's remaining() could hold the compressed data, which caller should ensure that `dest.remaining() >= maxCompressedLength(src.remaining())`
##########
common/src/main/java/org/apache/uniffle/common/compression/ZstdCodec.java:
##########
@@ -63,4 +63,18 @@ public void decompress(ByteBuffer src, int uncompressedLen, ByteBuffer dst, int
public byte[] compress(byte[] src) {
return Zstd.compress(src, compressionLevel);
}
+
+ @Override
+ public int compress(ByteBuffer src, ByteBuffer dest) {
+ try {
+ return Zstd.compress(dest, src.duplicate(), compressionLevel);
Review Comment:
As as SnappyCodec.
##########
common/src/test/java/org/apache/uniffle/common/compression/CompressionTest.java:
##########
@@ -79,5 +81,19 @@ public void testCompression(int size, Codec.Type type) {
codec.decompress(ByteBuffer.wrap(compressed), size, recycledDst, 0);
recycledDst.get(res);
assertArrayEquals(data, res);
+
+ // case4: use bytebuffer compress
+ ByteBuffer srcBuffer = ByteBuffer.allocateDirect(size);
Review Comment:
on heap byte buffer should also be supported.
##########
common/src/main/java/org/apache/uniffle/common/compression/SnappyCodec.java:
##########
@@ -64,4 +64,21 @@ public byte[] compress(byte[] src) {
throw new RssException("Failed to uncompress by Snappy", e);
}
}
+
+ @Override
+ public int compress(ByteBuffer src, ByteBuffer dest) {
Review Comment:
I already commented in another comment.
##########
common/src/main/java/org/apache/uniffle/common/compression/SnappyCodec.java:
##########
@@ -64,4 +64,20 @@ public byte[] compress(byte[] src) {
throw new RssException("Failed to uncompress by Snappy", e);
}
}
+
+ @Override
+ public int compress(ByteBuffer src, ByteBuffer dest) {
+ try {
+ int compressedSize = Snappy.compress(src.duplicate(), dest);
+ dest.position(compressedSize);
Review Comment:
And this is wrong.
For one thing, snappy should already update this position, for another thing, the position should be updated as
```
int offset = dest.position();
int compressedSize = Snappy.compress(src.duplicate(), dest);
dest.position(offset + compressedSize);
```
##########
common/src/main/java/org/apache/uniffle/common/compression/Codec.java:
##########
@@ -55,6 +55,20 @@ public static Codec newInstance(RssConf rssConf) {
*/
public abstract byte[] compress(byte[] src);
+ /**
+ * Compresses the data in buffer src into dest.
+ * dest ByteBuffer.remaining() must be exactly the size of the decompressed data.
+ * This method move the position of dest ByteBuffer,keep src ByteBuffer position.
Review Comment:
I'm not sure about this semantic.
LZ4 and Zstd compressors update both src and dest buffers' position, and it seems natural for ByteBuffers as the compression itself consumes data in bytebuffer.
However Snappy compressor doesn't do that for src buffer.
Could you check other similar codecs in Spark and Hadoop to see what's preferred behavior?
To be honest, I'm preferring update both positions for src and dest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org