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


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconServerConfigKeys.java:
##########
@@ -221,6 +221,16 @@ public final class  ReconServerConfigKeys {
       "ozone.recon.dn.metrics.collection.timeout";
   public static final String OZONE_RECON_DN_METRICS_COLLECTION_TIMEOUT_DEFAULT 
= "10m";
 
+  /**
+   * Maximum number of ContainerIDs to fetch from SCM per RPC call
+   * during container sync. Each ContainerID is approximately 12 bytes
+   * on the wire. Reduce this value on memory-constrained Recon nodes.
+   * Default: 500,000 (~16MB heap per batch, 8 calls for a 4M container 
cluster)

Review Comment:
   The "~16MB heap" is computed as 500K × ~32 bytes per JVM ContainerID object. 
But the wire size is 500K × 12 bytes = 6MB. These are different things and the 
comment doesn't distinguish them. Operators tuning this config for RPC limits 
care about wire size; operators tuning for memory care about heap size. Clarify 
both: e.g., "~6MB on the wire, ~16MB JVM heap per batch". So based on wire 
size, number of containers in single rpc call also can be more in default ?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.scm;
+
+import static 
org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_ID_BATCH_SIZE;
+import static 
org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_ID_BATCH_SIZE_DEFAULT;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import 
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
+import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ReconStorageContainerSyncHelper {
+
+  private static final String IPC_MAXIMUM_DATA_LENGTH = 
"ipc.maximum.data.length";
+  private static final int IPC_MAXIMUM_DATA_LENGTH_DEFAULT = 128 * 1024 * 1024;

Review Comment:
   Both these IPC constants can be directly used as hadoop's constants.Hadoop's 
`CommonConfigurationKeys` already exposes `IPC_MAXIMUM_DATA_LENGTH` and 
`IPC_MAXIMUM_DATA_LENGTH_DEFAULT` as public constants. if Hadoop ever changes 
these, Recon's copies won't update.  I think earlier also this was wrong, lets 
correct this in this PR.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.scm;
+
+import static 
org.apache.hadoop.fs.CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH;
+import static 
org.apache.hadoop.fs.CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH_DEFAULT;
+import static 
org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade.CONTAINER_METADATA_SIZE;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import 
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
+import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ReconStorageContainerSyncHelper {
+
+  private static final Logger LOG = LoggerFactory
+      .getLogger(ReconStorageContainerSyncHelper.class);
+
+  private final StorageContainerServiceProvider scmServiceProvider;
+  private final OzoneConfiguration ozoneConfiguration;
+  private final ReconContainerManager containerManager;
+
+  ReconStorageContainerSyncHelper(StorageContainerServiceProvider 
scmServiceProvider,
+                                  OzoneConfiguration ozoneConfiguration,
+                                  ReconContainerManager containerManager) {
+    this.scmServiceProvider = scmServiceProvider;
+    this.ozoneConfiguration = ozoneConfiguration;
+    this.containerManager = containerManager;
+  }
+
+  public boolean syncWithSCMContainerInfo() throws Exception {
+    try {
+      long totalContainerCount = scmServiceProvider.getContainerCount(
+          HddsProtos.LifeCycleState.CLOSED);
+      long containerCountPerCall =
+          getContainerCountPerCall(totalContainerCount);
+      ContainerID startContainerId = ContainerID.valueOf(1);
+      long retrievedContainerCount = 0;
+      if (totalContainerCount > 0) {
+        while (retrievedContainerCount < totalContainerCount) {
+          List<ContainerID> listOfContainers = scmServiceProvider.
+              getListOfContainerIDs(startContainerId,
+                  Long.valueOf(containerCountPerCall).intValue(),
+                  HddsProtos.LifeCycleState.CLOSED);
+          if (null != listOfContainers && !listOfContainers.isEmpty()) {
+            LOG.info("Got list of containers from SCM : {}", 
listOfContainers.size());
+            listOfContainers.forEach(containerID -> {
+              boolean isContainerPresentAtRecon = 
containerManager.containerExist(containerID);
+              if (!isContainerPresentAtRecon) {
+                try {
+                  ContainerWithPipeline containerWithPipeline =
+                      scmServiceProvider.getContainerWithPipeline(
+                          containerID.getId());
+                  containerManager.addNewContainer(containerWithPipeline);
+                } catch (IOException e) {
+                  LOG.error("Could not get container with pipeline " +
+                      "for container : {}", containerID);
+                }
+              }
+            });
+            long lastID = listOfContainers.get(listOfContainers.size() - 
1).getId();
+            startContainerId = ContainerID.valueOf(lastID + 1);
+          } else {
+            LOG.info("No containers found at SCM in CLOSED state");
+            return false;
+          }
+          retrievedContainerCount += containerCountPerCall;
+        }
+      }
+    } catch (Exception e) {
+      LOG.error("Unable to refresh Recon SCM DB Snapshot. ", e);
+      return false;
+    }
+    return true;
+  }
+
+  private long getContainerCountPerCall(long totalContainerCount) {

Review Comment:
   The "~16MB heap" is computed as 500K × ~32 bytes per JVM ContainerID object. 
But the wire size is 500K × 12 bytes = 6MB.  Check my comment in other place.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java:
##########
@@ -534,72 +538,13 @@ public void updateReconSCMDBWithNewSnapshot() throws 
IOException {
   }
 
   public boolean syncWithSCMContainerInfo()
-      throws IOException {
+      throws Exception {
     if (isSyncDataFromSCMRunning.compareAndSet(false, true)) {

Review Comment:
   Ok, this is fine.



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