swamirishi commented on code in PR #9550:
URL: https://github.com/apache/ozone/pull/9550#discussion_r2649991569
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestCodec.java:
##########
@@ -295,14 +298,13 @@ public static <T> void runTest(Codec<T> codec, T original,
static <T> void runTestBytes(T object, Codec<T> codec) throws IOException {
final byte[] array = codec.toPersistedFormat(object);
final Bytes fromArray = new Bytes(array);
-
- try (CodecBuffer buffer = codec.toCodecBuffer(object,
- CodecBuffer.Allocator.HEAP)) {
- final Bytes fromBuffer = new Bytes(buffer);
-
- assertEquals(fromArray.hashCode(), fromBuffer.hashCode());
- assertEquals(fromArray, fromBuffer);
- assertEquals(fromBuffer, fromArray);
+ for (CodecBuffer.Allocator allocator :
ImmutableList.of(CodecBuffer.Allocator.HEAP, CodecBuffer.Allocator.DIRECT)) {
Review Comment:
done
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBBatchOperation.java:
##########
@@ -80,26 +81,33 @@ private static String countSize2String(int count, long
size) {
* To implement {@link #equals(Object)} and {@link #hashCode()}
* based on the contents of the bytes.
*/
- static final class Bytes {
- private final byte[] array;
- private final CodecBuffer buffer;
+ static final class Bytes implements Closeable {
+ private AbstractSlice<?> slice;
/** Cache the hash value. */
- private final int hash;
+ private int hash;
Bytes(CodecBuffer buffer) {
- this.array = null;
- this.buffer = Objects.requireNonNull(buffer, "buffer == null");
- this.hash = buffer.asReadOnlyByteBuffer().hashCode();
+ Objects.requireNonNull(buffer, "buffer == null");
+ if (buffer.isDirect()) {
+ initWithDirectByteBuffer(buffer.asReadOnlyByteBuffer());
+ } else {
+ initWithByteArray(buffer.getArray());
+ }
}
Bytes(byte[] array) {
- this.array = array;
- this.buffer = null;
+ Objects.requireNonNull(array, "array == null");
+ initWithByteArray(array);
+ }
+
+ private void initWithByteArray(byte[] array) {
+ this.slice = new ManagedSlice(array);
this.hash = ByteBuffer.wrap(array).hashCode();
}
- ByteBuffer asReadOnlyByteBuffer() {
- return buffer.asReadOnlyByteBuffer();
+ private void initWithDirectByteBuffer(ByteBuffer byteBuffer) {
+ this.slice = new ManagedDirectSlice(byteBuffer);
+ this.hash = byteBuffer.hashCode();
}
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]