You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by ro...@apache.org on 2023/05/10 08:44:09 UTC
[incubator-uniffle] branch master updated: [#593][FOLLOWUP] Fix zstd compress dest ByteBuffer position
This is an automated email from the ASF dual-hosted git repository.
roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new 1ea1f1b1 [#593][FOLLOWUP] Fix zstd compress dest ByteBuffer position
1ea1f1b1 is described below
commit 1ea1f1b14acfd8674a03801fc4d16136d606dd74
Author: xumanbu <ma...@163.com>
AuthorDate: Wed May 10 16:44:03 2023 +0800
[#593][FOLLOWUP] Fix zstd compress dest ByteBuffer position
### What changes were proposed in this pull request?
Fix Zstd compress dest ByteBuffer position
### Why are the changes needed?
ZstdCodec compress method called with src&dest on Heap ByteBuffer, the dest ByteBuffer position will not update. should keep consistent with others Codec.
Fix: #593
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
UT
Co-authored-by: jam.xu <ja...@vipshop.com>
---
.../main/java/org/apache/uniffle/common/compression/ZstdCodec.java | 6 ++++--
.../java/org/apache/uniffle/common/compression/CompressionTest.java | 3 ++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/common/src/main/java/org/apache/uniffle/common/compression/ZstdCodec.java b/common/src/main/java/org/apache/uniffle/common/compression/ZstdCodec.java
index 34987ecd..b9981735 100644
--- a/common/src/main/java/org/apache/uniffle/common/compression/ZstdCodec.java
+++ b/common/src/main/java/org/apache/uniffle/common/compression/ZstdCodec.java
@@ -76,9 +76,11 @@ public class ZstdCodec extends Codec {
return Zstd.compress(dest, src.duplicate(), compressionLevel);
}
if (!src.isDirect() && !dest.isDirect()) {
- long compressedSize = Zstd.compressByteArray(dest.array(), dest.position(), dest.remaining(), src.array(),
+ int destOff = dest.position();
+ int compressedSize = (int) Zstd.compressByteArray(dest.array(), dest.position(), dest.remaining(), src.array(),
src.position(), src.remaining(), compressionLevel);
- return (int) compressedSize;
+ dest.position(destOff + compressedSize);
+ return compressedSize;
}
} catch (Exception e) {
throw new RssException("Failed to compress by Zstd", e);
diff --git a/common/src/test/java/org/apache/uniffle/common/compression/CompressionTest.java b/common/src/test/java/org/apache/uniffle/common/compression/CompressionTest.java
index cf76b1fa..5efabb77 100644
--- a/common/src/test/java/org/apache/uniffle/common/compression/CompressionTest.java
+++ b/common/src/test/java/org/apache/uniffle/common/compression/CompressionTest.java
@@ -123,7 +123,8 @@ public class CompressionTest {
assertTrue(e instanceof IllegalStateException);
}
} else {
- codec.compress(srcBuffer, destBuffer);
+ int compressedLength = codec.compress(srcBuffer, destBuffer);
+ assertEquals(destBuffer.position(), destOffset + compressedLength);
assertEquals(srcBuffer.position(), destOffset);
destBuffer.flip();
destBuffer.position(destOffset);