szetszwo commented on code in PR #10381:
URL: https://github.com/apache/ozone/pull/10381#discussion_r3326153512


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/metadata/SequenceIdTypeCodec.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.scm.metadata;
+
+import jakarta.annotation.Nonnull;
+import org.apache.hadoop.hdds.scm.ha.SequenceIdType;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.CodecBuffer;
+import org.apache.hadoop.hdds.utils.db.CodecException;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+
+/**
+ * Codec to serialize/deserialize {@link SequenceIdType}.
+ */
+public final class SequenceIdTypeCodec implements Codec<SequenceIdType> {

Review Comment:
   - We should cache all the results (instead of encoding to/decoding from 
string every time)
   - Since SequenceIdType is very small, let's move the codec to SequenceIdType.



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/metadata/TestSequenceIdTypeCodec.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.scm.metadata;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.hadoop.hdds.scm.ha.SequenceIdType;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.CodecTestUtil;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Testing serialization and deserialization of SequenceIdType objects to/from 
RocksDB.
+ */
+public class TestSequenceIdTypeCodec {
+
+  private final Codec<SequenceIdType> enumCodec = SequenceIdTypeCodec.get();
+  private final Codec<String> stringCodec = StringCodec.get();
+
+  @Test
+  public void testCodecBuffersWithOzoneTestUtil() throws Exception {
+    for (SequenceIdType type : SequenceIdType.values()) {
+      // Verify codec compatibility with heap and direct byte buffers.
+      CodecTestUtil.runTest(enumCodec, type, null, null);

Review Comment:
   Pass also the serializedSize.



-- 
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]

Reply via email to