This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new d6fefd0b85 HDDS-8664. Support CodecBuffer for some of the remaining 
protobuf v2 codecs in hadoop-ozone. (#4751)
d6fefd0b85 is described below

commit d6fefd0b8574713babc8c61e9611a0103c3a6487
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Mon May 22 20:48:03 2023 +0800

    HDDS-8664. Support CodecBuffer for some of the remaining protobuf v2 codecs 
in hadoop-ozone. (#4751)
---
 .../hadoop/hdds/protocol/DatanodeDetails.java      | 14 ++++-
 .../hadoop/hdds/utils/db/DelegatedCodec.java       | 11 ++--
 .../hadoop/ozone/om/helpers/SnapshotInfo.java      | 12 +++++
 .../ozone/snapshot/SnapshotDiffReportOzone.java    | 14 +++++
 .../ozone/om/codec/OmDBDiffReportEntryCodec.java   | 61 ----------------------
 .../ozone/om/codec/OmDBSnapshotInfoCodec.java      | 58 --------------------
 .../hadoop/ozone/om/OmMetadataManagerImpl.java     |  3 +-
 .../apache/hadoop/ozone/om/OmSnapshotManager.java  |  3 +-
 .../hadoop/ozone/om/codec/OMDBDefinition.java      |  2 +-
 .../om/service/TestSnapshotDiffCleanupService.java |  3 +-
 .../codec/ContainerReplicaHistoryListCodec.java    | 51 ------------------
 .../ozone/recon/codec/DatanodeDetailsCodec.java    | 50 ------------------
 .../recon/scm/ContainerReplicaHistoryList.java     | 12 +++++
 .../ozone/recon/scm/ReconSCMDBDefinition.java      |  3 +-
 .../ozone/recon/spi/impl/ReconDBDefinition.java    |  5 +-
 15 files changed, 64 insertions(+), 238 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
index 86d300e477..b068d8725c 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -38,6 +38,9 @@ import org.apache.hadoop.hdds.scm.net.NodeImpl;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import org.apache.hadoop.hdds.upgrade.BelongsToHDDSLayoutVersion;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.DelegatedCodec;
+import org.apache.hadoop.hdds.utils.db.Proto2Codec;
 import org.apache.hadoop.ozone.ClientVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -63,6 +66,15 @@ public class DatanodeDetails extends NodeImpl implements
   private static final Logger LOG =
       LoggerFactory.getLogger(DatanodeDetails.class);
 
+  private static final Codec<DatanodeDetails> CODEC = new DelegatedCodec<>(
+      Proto2Codec.get(HddsProtos.ExtendedDatanodeDetailsProto.class),
+      DatanodeDetails::getFromProtoBuf,
+      DatanodeDetails::getExtendedProtoBufMessage);
+
+  public static Codec<DatanodeDetails> getCodec() {
+    return CODEC;
+  }
+
   /**
    * DataNode's unique identifier in the cluster.
    */
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java
index 6960c8b96c..738a78f874 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java
@@ -33,7 +33,7 @@ public class DelegatedCodec<T, DELEGATE> implements Codec<T> {
   private final Codec<DELEGATE> delegate;
   private final CheckedFunction<DELEGATE, T, IOException> forward;
   private final CheckedFunction<T, DELEGATE, IOException> backward;
-  private final boolean immutable;
+  private final boolean shallowCopy;
 
   /**
    * Construct a {@link Codec} using the given delegate.
@@ -41,16 +41,17 @@ public class DelegatedCodec<T, DELEGATE> implements 
Codec<T> {
    * @param delegate the delegate {@link Codec}
    * @param forward a function to convert {@link DELEGATE} to {@link T}.
    * @param backward a function to convert {@link T} back to {@link DELEGATE}.
-   * @param immutable are the objects in {@link T} immutable?
+   * @param shallowCopy Should it use shallow copy
+   *                    in {@link #copyObject(Object)}?
    */
   public DelegatedCodec(Codec<DELEGATE> delegate,
       CheckedFunction<DELEGATE, T, IOException> forward,
       CheckedFunction<T, DELEGATE, IOException> backward,
-      boolean immutable) {
+      boolean shallowCopy) {
     this.delegate = delegate;
     this.forward = forward;
     this.backward = backward;
-    this.immutable = immutable;
+    this.shallowCopy = shallowCopy;
   }
 
   /** The same as new DelegatedCodec(delegate, forward, backward, false). */
@@ -89,7 +90,7 @@ public class DelegatedCodec<T, DELEGATE> implements Codec<T> {
 
   @Override
   public T copyObject(T message) {
-    if (immutable) {
+    if (shallowCopy) {
       return message;
     }
     try {
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java
index 31f67fbdba..a6a4a64780 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java
@@ -20,6 +20,9 @@ package org.apache.hadoop.ozone.om.helpers;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.DelegatedCodec;
+import org.apache.hadoop.hdds.utils.db.Proto2Codec;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.audit.Auditable;
 import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
@@ -48,6 +51,15 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
  * for the snapshot path & global amongst other necessary fields.
  */
 public final class SnapshotInfo implements Auditable {
+  private static final Codec<SnapshotInfo> CODEC = new DelegatedCodec<>(
+      Proto2Codec.get(OzoneManagerProtocolProtos.SnapshotInfo.class),
+      SnapshotInfo::getFromProtobuf,
+      SnapshotInfo::getProtobuf,
+      true);
+
+  public static Codec<SnapshotInfo> getCodec() {
+    return CODEC;
+  }
 
   /**
    * SnapshotStatus enum composed of
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java
index f52ca5c488..9b470e3bbc 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/snapshot/SnapshotDiffReportOzone.java
@@ -21,8 +21,12 @@ package org.apache.hadoop.ozone.snapshot;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.DelegatedCodec;
+import org.apache.hadoop.hdds.utils.db.Proto2Codec;
 import org.apache.hadoop.ozone.OFSPath;
 import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DiffReportEntryProto;
 import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotDiffReportProto;
 
 import java.nio.charset.StandardCharsets;
@@ -37,6 +41,16 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
 public class SnapshotDiffReportOzone
     extends org.apache.hadoop.hdfs.protocol.SnapshotDiffReport {
 
+  private static final Codec<DiffReportEntry> CODEC = new DelegatedCodec<>(
+      Proto2Codec.get(DiffReportEntryProto.class),
+      SnapshotDiffReportOzone::fromProtobufDiffReportEntry,
+      SnapshotDiffReportOzone::toProtobufDiffReportEntry,
+      true);
+
+  public static Codec<DiffReportEntry> getDiffReportEntryCodec() {
+    return CODEC;
+  }
+
   private static final String LINE_SEPARATOR = System.getProperty(
       "line.separator", "\n");
 
diff --git 
a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBDiffReportEntryCodec.java
 
b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBDiffReportEntryCodec.java
deleted file mode 100644
index 455a730f80..0000000000
--- 
a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBDiffReportEntryCodec.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.ozone.om.codec;
-
-import java.io.IOException;
-import org.apache.hadoop.hdds.utils.db.Codec;
-import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
-import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Codec to encode DiffReportEntry as byte array.
- */
-public class OmDBDiffReportEntryCodec implements
-    Codec<org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry> {
-
-  @Override
-  public byte[] toPersistedFormat(
-      org.apache.hadoop.hdfs.protocol
-          .SnapshotDiffReport.DiffReportEntry object)
-      throws IOException {
-    checkNotNull(object, "Null object can't be converted to byte array.");
-    return SnapshotDiffReportOzone.toProtobufDiffReportEntry(object)
-        .toByteArray();
-  }
-
-  @Override
-  public org.apache.hadoop.hdfs.protocol
-      .SnapshotDiffReport.DiffReportEntry fromPersistedFormat(
-      byte[] rawData) throws IOException {
-    checkNotNull(rawData,
-        "Null byte array can't be converted to " + "real object.");
-    return SnapshotDiffReportOzone.fromProtobufDiffReportEntry(
-        OzoneManagerProtocolProtos.DiffReportEntryProto.parseFrom(rawData));
-  }
-
-  @Override
-  public org.apache.hadoop.hdfs.protocol
-      .SnapshotDiffReport.DiffReportEntry copyObject(
-      org.apache.hadoop.hdfs.protocol
-          .SnapshotDiffReport.DiffReportEntry object) {
-    // Note: Not really a "copy". from OmDBDiffReportEntryCodec
-    return object;
-  }
-}
diff --git 
a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
 
b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
deleted file mode 100644
index d7da0daf96..0000000000
--- 
a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.ozone.om.codec;
-
-import org.apache.hadoop.hdds.utils.db.Codec;
-import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
-import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Codec to encode SnapshotInfo as byte array.
- */
-public class OmDBSnapshotInfoCodec implements Codec<SnapshotInfo> {
-  private static final Logger LOG =
-      LoggerFactory.getLogger(OmDBSnapshotInfoCodec.class);
-
-  @Override
-  public byte[] toPersistedFormat(SnapshotInfo object) throws IOException {
-    checkNotNull(object, "Null object can't be converted to byte array.");
-    return object.getProtobuf().toByteArray();
-  }
-
-  @Override
-  public SnapshotInfo fromPersistedFormat(byte[] rawData)
-      throws IOException {
-    checkNotNull(rawData, "Null byte array can't be converted to " +
-        "real object.");
-    return SnapshotInfo.getFromProtobuf(
-        OzoneManagerProtocolProtos.SnapshotInfo.parseFrom(rawData));
-  }
-
-  @Override
-  public SnapshotInfo copyObject(SnapshotInfo object) {
-    // Note: Not really a "copy". from OMDBSnapshotInfoCodec
-    return object;
-  }
-}
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
index e064e835b8..a51d544028 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
@@ -56,7 +56,6 @@ import org.apache.hadoop.ozone.OmUtils;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.common.BlockGroup;
 import org.apache.hadoop.hdds.utils.TransactionInfoCodec;
-import org.apache.hadoop.ozone.om.codec.OmDBSnapshotInfoCodec;
 import org.apache.hadoop.ozone.om.codec.OmDBUserPrincipalInfoCodec;
 import org.apache.hadoop.ozone.om.codec.OmDirectoryInfoCodec;
 import org.apache.hadoop.ozone.om.codec.OmMultipartKeyInfoCodec;
@@ -599,7 +598,7 @@ public class OmMetadataManagerImpl implements 
OMMetadataManager,
         .addCodec(OmDBTenantState.class, new OmDBTenantStateCodec())
         .addCodec(OmDBAccessIdInfo.class, OmDBAccessIdInfo.getCodec())
         .addCodec(OmDBUserPrincipalInfo.class, new 
OmDBUserPrincipalInfoCodec())
-        .addCodec(SnapshotInfo.class, new OmDBSnapshotInfoCodec());
+        .addCodec(SnapshotInfo.class, SnapshotInfo.getCodec());
   }
 
   /**
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
index 076aba15b1..92ee5e5c63 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
@@ -52,7 +52,6 @@ import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
 import org.apache.hadoop.hdds.utils.db.managed.ManagedColumnFamilyOptions;
 import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
 import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
-import org.apache.hadoop.ozone.om.codec.OmDBDiffReportEntryCodec;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
 import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
@@ -353,7 +352,7 @@ public final class OmSnapshotManager implements 
AutoCloseable {
     final CodecRegistry.Builder registry = CodecRegistry.newBuilder();
     // DiffReportEntry codec for Diff Report.
     registry.addCodec(SnapshotDiffReportOzone.DiffReportEntry.class,
-        new OmDBDiffReportEntryCodec());
+        SnapshotDiffReportOzone.getDiffReportEntryCodec());
     registry.addCodec(SnapshotDiffJob.class,
         new SnapshotDiffJob.SnapshotDiffJobCodec());
     return registry.build();
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java
index bef8aa2604..3bcec40e87 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java
@@ -228,7 +228,7 @@ public class OMDBDefinition implements DBDefinition {
           String.class,  // snapshot path
           new StringCodec(),
           SnapshotInfo.class,
-          new OmDBSnapshotInfoCodec());
+          SnapshotInfo.getCodec());
 
   /**
    * SnapshotRenamedTable that complements the keyTable (or fileTable)
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestSnapshotDiffCleanupService.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestSnapshotDiffCleanupService.java
index 041a1fede2..7056cc873d 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestSnapshotDiffCleanupService.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestSnapshotDiffCleanupService.java
@@ -27,7 +27,6 @@ import 
org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
 import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
 import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator;
 import org.apache.hadoop.ozone.om.OzoneManager;
-import org.apache.hadoop.ozone.om.codec.OmDBDiffReportEntryCodec;
 import org.apache.hadoop.ozone.om.snapshot.SnapshotDiffJob;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus;
@@ -171,7 +170,7 @@ public class TestSnapshotDiffCleanupService {
     final CodecRegistry.Builder b = CodecRegistry.newBuilder();
     // DiffReportEntry codec for Diff Report.
     b.addCodec(SnapshotDiffReportOzone.DiffReportEntry.class,
-        new OmDBDiffReportEntryCodec());
+        SnapshotDiffReportOzone.getDiffReportEntryCodec());
     b.addCodec(SnapshotDiffJob.class,
         new SnapshotDiffJob.SnapshotDiffJobCodec());
     codecRegistry = b.build();
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/ContainerReplicaHistoryListCodec.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/ContainerReplicaHistoryListCodec.java
deleted file mode 100644
index 5cf575d6ad..0000000000
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/ContainerReplicaHistoryListCodec.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.ozone.recon.codec;
-
-import 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerReplicaHistoryListProto;
-import org.apache.hadoop.hdds.utils.db.Codec;
-import org.apache.hadoop.ozone.recon.scm.ContainerReplicaHistoryList;
-
-import java.io.IOException;
-
-/**
- * Codec for ContainerReplicaHistoryList.
- */
-public class ContainerReplicaHistoryListCodec
-    implements Codec<ContainerReplicaHistoryList> {
-
-  @Override
-  public byte[] toPersistedFormat(ContainerReplicaHistoryList obj) {
-    return obj.toProto().toByteArray();
-  }
-
-  @Override
-  public ContainerReplicaHistoryList fromPersistedFormat(byte[] rawData)
-      throws IOException {
-    return ContainerReplicaHistoryList.fromProto(
-        ContainerReplicaHistoryListProto.parseFrom(rawData));
-  }
-
-  @Override
-  public ContainerReplicaHistoryList copyObject(
-      ContainerReplicaHistoryList obj) {
-    return obj;
-  }
-}
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/DatanodeDetailsCodec.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/DatanodeDetailsCodec.java
deleted file mode 100644
index 96ae806c87..0000000000
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/codec/DatanodeDetailsCodec.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.ozone.recon.codec;
-
-import static org.apache.hadoop.hdds.protocol.proto
-    .HddsProtos.ExtendedDatanodeDetailsProto.PARSER;
-
-import java.io.IOException;
-
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
-import org.apache.hadoop.hdds.utils.db.Codec;
-
-/**
- * Codec for DatanodeDetails.
- */
-public class DatanodeDetailsCodec implements Codec<DatanodeDetails> {
-
-  @Override
-  public byte[] toPersistedFormat(DatanodeDetails object) throws IOException {
-    return object.getExtendedProtoBufMessage().toByteArray();
-  }
-
-  @Override
-  public DatanodeDetails fromPersistedFormat(byte[] rawData)
-      throws IOException {
-    return DatanodeDetails.getFromProtoBuf(PARSER.parseFrom(rawData));
-  }
-
-  @Override
-  public DatanodeDetails copyObject(DatanodeDetails object) {
-    return object;
-  }
-}
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java
index 0a196652f5..0640ef46fe 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ContainerReplicaHistoryList.java
@@ -24,6 +24,9 @@ import java.util.List;
 
 import 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerReplicaHistoryListProto;
 import 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerReplicaHistoryProto;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.DelegatedCodec;
+import org.apache.hadoop.hdds.utils.db.Proto2Codec;
 
 /**
  * A list of ContainerReplicaHistory.
@@ -31,6 +34,15 @@ import 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerReplicaHistoryP
  * For Recon DB table definition.
  */
 public class ContainerReplicaHistoryList {
+  private static final Codec<ContainerReplicaHistoryList> CODEC
+      = new DelegatedCodec<>(Proto2Codec.get(
+      ContainerReplicaHistoryListProto.class),
+      ContainerReplicaHistoryList::fromProto,
+      ContainerReplicaHistoryList::toProto);
+
+  public static Codec<ContainerReplicaHistoryList> getCodec() {
+    return CODEC;
+  }
 
   private List<ContainerReplicaHistory> replicaHistories;
 
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java
index e56a66b831..c59772d1cc 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java
@@ -25,7 +25,6 @@ import org.apache.hadoop.hdds.protocol.DatanodeDetails;
 import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
 import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
 import org.apache.hadoop.ozone.recon.ReconServerConfigKeys;
-import org.apache.hadoop.ozone.recon.codec.DatanodeDetailsCodec;
 import org.apache.hadoop.ozone.recon.codec.ReconNodeDBKeyCodec;
 
 /**
@@ -42,7 +41,7 @@ public class ReconSCMDBDefinition extends SCMDBDefinition {
           UUID.class,
           new ReconNodeDBKeyCodec(),
           DatanodeDetails.class,
-          new DatanodeDetailsCodec());
+          DatanodeDetails.getCodec());
 
   @Override
   public String getName() {
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBDefinition.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBDefinition.java
index 88b7c99d5a..5c8a2baf3f 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBDefinition.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBDefinition.java
@@ -24,7 +24,6 @@ import org.apache.hadoop.hdds.utils.db.LongCodec;
 import org.apache.hadoop.ozone.recon.ReconServerConfigKeys;
 import org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix;
 import org.apache.hadoop.ozone.recon.api.types.KeyPrefixContainer;
-import org.apache.hadoop.ozone.recon.codec.ContainerReplicaHistoryListCodec;
 import org.apache.hadoop.ozone.recon.codec.NSSummaryCodec;
 import org.apache.hadoop.ozone.recon.scm.ContainerReplicaHistoryList;
 import org.apache.hadoop.ozone.recon.api.types.NSSummary;
@@ -74,7 +73,7 @@ public class ReconDBDefinition implements DBDefinition {
           Long.class,
           LongCodec.get(),
           ContainerReplicaHistoryList.class,
-          new ContainerReplicaHistoryListCodec());
+          ContainerReplicaHistoryList.getCodec());
 
   public static final DBColumnFamilyDefinition<Long, NSSummary>
       NAMESPACE_SUMMARY = new DBColumnFamilyDefinition<Long, NSSummary>(
@@ -92,7 +91,7 @@ public class ReconDBDefinition implements DBDefinition {
           Long.class,
           LongCodec.get(),
           ContainerReplicaHistoryList.class,
-          new ContainerReplicaHistoryListCodec());
+          ContainerReplicaHistoryList.getCodec());
 
   @Override
   public String getName() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to