You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2023/05/05 15:46:57 UTC

[GitHub] [ozone] szetszwo opened a new pull request, #4666: HDDS-8542. In RDBTable, add a put method using RocksDB ByteBuffer APIs.

szetszwo opened a new pull request, #4666:
URL: https://github.com/apache/ozone/pull/4666

   ## What changes were proposed in this pull request?
   
   - Add a put method to use RocksDB ByteBuffer APIs.
   - Support ByteBuffer methods in Codec and some of the implementations.  (Will work on other implementations in other JIRAs.)
   
   ## What is the link to the Apache JIRA
   
   HDDS-8542
   
   ## How was this patch tested?
   
   Add new tests to test the codec implementations.


-- 
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@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on a diff in pull request #4666: HDDS-8542. In RDBTable, add a put method using RocksDB ByteBuffer APIs.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #4666:
URL: https://github.com/apache/ozone/pull/4666#discussion_r1186769537


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestCodec.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.utils.db;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.WeakReference;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Test {@link Codec} implementations.
+ */
+public final class TestCodec {
+  static final Logger LOG = LoggerFactory.getLogger(TestCodec.class);
+  static final int NUM_LOOPS = 10;
+
+  /** Force gc to check leakage. */
+  static void gc() throws InterruptedException {
+    // use WeakReference to detect gc
+    Object obj = new Object();
+    final WeakReference<Object> weakRef = new WeakReference<>(obj);
+    obj = null;
+
+    // loop until gc has completed.
+    for (int i = 0; weakRef.get() != null; i++) {
+      LOG.info("gc {}", i);
+      System.gc();
+      Thread.sleep(100);
+    }
+    CodecBuffer.assertNoLeaks();
+  }
+
+  @Test
+  public void testIntegerCodec() throws Exception {
+    final IntegerCodec codec = new IntegerCodec();
+    runTest(codec, 0, Integer.BYTES);
+    runTest(codec, 1, Integer.BYTES);
+    runTest(codec, -1, Integer.BYTES);
+    runTest(codec, Integer.MAX_VALUE, Integer.BYTES);
+    runTest(codec, Integer.MIN_VALUE, Integer.BYTES);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final int original = ThreadLocalRandom.current().nextInt();
+      runTest(codec, original, Integer.BYTES);
+    }
+    gc();
+  }
+
+  @Test
+  public void testLongCodec() throws Exception {
+    final LongCodec codec = new LongCodec();
+    runTest(codec, 0L, Long.BYTES);
+    runTest(codec, 1L, Long.BYTES);
+    runTest(codec, -1L, Long.BYTES);
+    runTest(codec, Long.MAX_VALUE, Long.BYTES);
+    runTest(codec, Long.MIN_VALUE, Long.BYTES);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final long original = ThreadLocalRandom.current().nextLong();
+      runTest(codec, original, Long.BYTES);
+    }
+    gc();
+  }
+
+  @Test
+  public void testStringCodec() throws Exception {
+    final StringCodec codec = new StringCodec();
+    runTest(codec, "", 0);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final String original = "test" + ThreadLocalRandom.current().nextLong();
+      runTest(codec, original, original.length());
+    }
+    gc();
+  }
+
+  static <T> void runTest(Codec<T> codec, T original,
+      Integer serializedSize) throws Exception {
+    Assertions.assertTrue(codec.supportCodecBuffer());
+
+    // serialize to byte[]
+    final byte[] array = codec.toPersistedFormat(original);
+    if (serializedSize != null) {
+      Assertions.assertEquals(serializedSize, array.length);

Review Comment:
   That's a good point! Thanks.



-- 
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@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo merged pull request #4666: HDDS-8542. In RDBTable, add a put method using RocksDB ByteBuffer APIs.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo merged PR #4666:
URL: https://github.com/apache/ozone/pull/4666


-- 
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@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a diff in pull request #4666: HDDS-8542. In RDBTable, add a put method using RocksDB ByteBuffer APIs.

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #4666:
URL: https://github.com/apache/ozone/pull/4666#discussion_r1186732233


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestCodec.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.utils.db;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.WeakReference;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Test {@link Codec} implementations.
+ */
+public final class TestCodec {
+  static final Logger LOG = LoggerFactory.getLogger(TestCodec.class);
+  static final int NUM_LOOPS = 10;
+
+  /** Force gc to check leakage. */
+  static void gc() throws InterruptedException {
+    // use WeakReference to detect gc
+    Object obj = new Object();
+    final WeakReference<Object> weakRef = new WeakReference<>(obj);
+    obj = null;
+
+    // loop until gc has completed.
+    for (int i = 0; weakRef.get() != null; i++) {
+      LOG.info("gc {}", i);
+      System.gc();
+      Thread.sleep(100);
+    }
+    CodecBuffer.assertNoLeaks();
+  }
+
+  @Test
+  public void testIntegerCodec() throws Exception {
+    final IntegerCodec codec = new IntegerCodec();
+    runTest(codec, 0, Integer.BYTES);
+    runTest(codec, 1, Integer.BYTES);
+    runTest(codec, -1, Integer.BYTES);
+    runTest(codec, Integer.MAX_VALUE, Integer.BYTES);
+    runTest(codec, Integer.MIN_VALUE, Integer.BYTES);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final int original = ThreadLocalRandom.current().nextInt();
+      runTest(codec, original, Integer.BYTES);
+    }
+    gc();
+  }
+
+  @Test
+  public void testLongCodec() throws Exception {
+    final LongCodec codec = new LongCodec();
+    runTest(codec, 0L, Long.BYTES);
+    runTest(codec, 1L, Long.BYTES);
+    runTest(codec, -1L, Long.BYTES);
+    runTest(codec, Long.MAX_VALUE, Long.BYTES);
+    runTest(codec, Long.MIN_VALUE, Long.BYTES);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final long original = ThreadLocalRandom.current().nextLong();
+      runTest(codec, original, Long.BYTES);
+    }
+    gc();
+  }
+
+  @Test
+  public void testStringCodec() throws Exception {
+    final StringCodec codec = new StringCodec();
+    runTest(codec, "", 0);
+
+    for (int i = 0; i < NUM_LOOPS; i++) {
+      final String original = "test" + ThreadLocalRandom.current().nextLong();
+      runTest(codec, original, original.length());
+    }
+    gc();
+  }
+
+  static <T> void runTest(Codec<T> codec, T original,
+      Integer serializedSize) throws Exception {
+    Assertions.assertTrue(codec.supportCodecBuffer());
+
+    // serialize to byte[]
+    final byte[] array = codec.toPersistedFormat(original);
+    if (serializedSize != null) {
+      Assertions.assertEquals(serializedSize, array.length);

Review Comment:
   This would fail if String has multibyte chars.  Should pass `String.getBytes(UTF_8).length` instead of `String.length()`.  This is not a problem with the current state of the code, since `runTest` is only called with Latin1 strings, but could be improved in the future.



-- 
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@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on pull request #4666: HDDS-8542. In RDBTable, add a put method using RocksDB ByteBuffer APIs.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #4666:
URL: https://github.com/apache/ozone/pull/4666#issuecomment-1537268386

   @adoroszlai , thanks a lot for reviewing this!


-- 
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@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org