devmadhuu commented on code in PR #8895:
URL: https://github.com/apache/ozone/pull/8895#discussion_r2285221417


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfoLight.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.om.helpers;
+
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+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.protocol.proto.OzoneManagerProtocolProtos;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartKeyInfoLight;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfoLight;
+
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+/**
+ * This class is the light-weight version of OmMultipartKeyInfo.
+ * It is used by Recon to reduce payload and deserialization cost.
+ */
+public class OmMultipartKeyInfoLight {
+
+  private static final Codec<OmMultipartKeyInfoLight> CODEC = new 
DelegatedCodec<>(
+      Proto2Codec.get(MultipartKeyInfoLight.getDefaultInstance()),
+      OmMultipartKeyInfoLight::getFromProtobuf,
+      OmMultipartKeyInfoLight::getProtobuf,
+      OmMultipartKeyInfoLight.class);
+
+  private final String uploadID;
+  private final long creationTime;
+  private final ReplicationConfig replicationConfig;
+  private final Map<Integer, PartKeyInfoLight> partKeyInfoMap;
+  private final long objectID;
+  private final long updateID;
+  private final long parentID;
+
+  public OmMultipartKeyInfoLight(Builder b) {
+    this.uploadID = b.uploadID;
+    this.creationTime = b.creationTime;
+    this.replicationConfig = b.replicationConfig;
+    this.partKeyInfoMap = b.partKeyInfoMap;
+    this.objectID = b.objectID;
+    this.updateID = b.updateID;
+    this.parentID = b.parentID;
+  }
+
+  public static Codec<OmMultipartKeyInfoLight> getCodec() {
+    return CODEC;
+  }
+
+  public String getUploadID() {
+    return uploadID;
+  }
+
+  public long getCreationTime() {
+    return creationTime;
+  }
+
+  public ReplicationConfig getReplicationConfig() {
+    return replicationConfig;
+  }
+
+  public Map<Integer, PartKeyInfoLight> getPartKeyInfoMap() {
+    return partKeyInfoMap;
+  }
+
+  public long getObjectID() {
+    return objectID;
+  }
+
+  public long getUpdateID() {
+    return updateID;
+  }
+
+  public long getParentID() {
+    return parentID;
+  }
+
+  public static OmMultipartKeyInfoLight getFromProtobuf(
+      MultipartKeyInfoLight multipartKeyInfoLight) {
+    return new Builder()
+        .setUploadID(multipartKeyInfoLight.getUploadID())
+        .setCreationTime(multipartKeyInfoLight.getCreationTime())
+        .setReplicationConfig(
+            ReplicationConfig.fromProto(
+                multipartKeyInfoLight.getType(),
+                multipartKeyInfoLight.getFactor(),
+                multipartKeyInfoLight.getEcReplicationConfig()
+            ))
+        .setPartKeyInfoMap(
+            multipartKeyInfoLight.getPartKeyInfoListList().stream()
+                .collect(Collectors.toMap(
+                    PartKeyInfoLight::getPartNumber,
+                    partKeyInfo -> partKeyInfo,
+                    (v1, v2) -> v1,
+                    TreeMap::new
+                )))
+        .setObjectID(multipartKeyInfoLight.getObjectID())
+        .setUpdateID(multipartKeyInfoLight.getUpdateID())
+        .setParentID(multipartKeyInfoLight.getParentID())
+        .build();
+  }
+
+  public MultipartKeyInfoLight getProtobuf() {

Review Comment:
   I don't think, this will be needed. If this lightweight proto object will be 
used only in Recon for decode and not writing back  to DB which Recon doesn't 
do, then can we use 
[this](https://github.com/apache/ozone/blob/8d1a0adf7c228ff4df0aa678cd851f3b3c46c687/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/DelegatedCodec.java#L117)
 ?



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