devmadhuu commented on code in PR #9842:
URL: https://github.com/apache/ozone/pull/9842#discussion_r2884434786
##########
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 {
Review Comment:
The helper already catches all Exception internally and returns false — so
the throws Exception is misleading. The facade should declare throws
IOException (or nothing if the helper swallows everything).
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconStorageContainerSyncHelper.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED;
+import static
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
+import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
+import org.junit.jupiter.api.Test;
+
+class TestReconStorageContainerSyncHelper {
Review Comment:
Can we add a test verifying the multi-page pagination path — specifically,
that the startContainerId is correctly advanced to lastID + 1 after each batch,
and that a second call is made with the updated start ID. A cluster with
hundreds of thousands of containers will always hit the paginated path.
##########
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;
Review Comment:
We are importing `CONTAINER_METADATA_SIZE` from
`ReconStorageContainerManagerFacade`. Since the helper now owns the
`getContainerCountPerCall() `logic, the constant (and the new
`CONTAINER_ID_SIZE`) should live in the helper or a shared constants class.
##########
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:
```suggestion
if (isSyncDataFromSCMRunning.compareAndSet(false, true)) {
try {
return containerSyncHelper.syncWithSCMContainerInfo();
} finally {
isSyncDataFromSCMRunning.compareAndSet(true, false);
}
}
LOG.debug("SCM DB sync is already running.");
return false;
```
##########
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:
Earlier, CONTAINER_METADATA_SIZE was defined as 1MB to estimate a
ContainerInfo object. A ContainerID proto is ~8–12 bytes. With an IPC max of
128MB, the old code limited batches to floor(128MB / 1MB) = 128 containers per
call. The new code does the same — 128 IDs per call — when it could safely
fetch floor(128MB / 12 bytes) ≈ 5.5 million IDs per call. This means the change
may actually increase the number of RPCs instead of reducing them. So I think,
we should test with large set of container Ids specially when a cluster will
have 4-5 millions CLOSED containers and record the SCM latency and impact.
Because that was the whole objective behind why this JIRA was raised. And based
on impact, we should think of innovative way to handle impact on SCM as well as
rpc message length also should not exceed default 128 MB.
--
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]