priyeshkaratha commented on code in PR #9719:
URL: https://github.com/apache/ozone/pull/9719#discussion_r2791183291


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -1680,4 +1680,55 @@ public void reconcileContainer(long longContainerID) 
throws IOException {
       throw ex;
     }
   }
+
+  @Override
+  public void acknowledgeMissingContainer(long longContainerID) throws 
IOException {
+    ContainerID containerID = ContainerID.valueOf(longContainerID);
+    final Map<String, String> auditMap = new HashMap<>();
+    auditMap.put("containerID", containerID.toString());
+
+    try {
+      ContainerInfo containerInfo = 
scm.getContainerManager().getContainer(containerID);
+      Set<ContainerReplica> replicas = 
scm.getContainerManager().getContainerReplicas(containerID);
+      if (replicas != null && !replicas.isEmpty()) {
+        throw new IOException("Container " + longContainerID +
+            " has " + replicas.size() + " replicas and cannot be acknowledged 
as missing");
+      }
+
+      if (containerInfo.getNumberOfKeys() == 0) {
+        throw new IOException("Container " + longContainerID + " is empty (0 
keys) and cannot be acknowledged.");
+      }
+
+      HddsProtos.ContainerInfoProto updatedProto = 
containerInfo.getProtobuf().toBuilder()
+          .setAckMissing(true)
+          .build();
+      scm.getContainerManager().updateContainerInfo(containerID, updatedProto);
+
+      
AUDIT.logWriteSuccess(buildAuditMessageForSuccess(SCMAction.ACKNOWLEDGE_MISSING_CONTAINER,
 auditMap));
+    } catch (IOException ex) {
+      
AUDIT.logWriteFailure(buildAuditMessageForFailure(SCMAction.ACKNOWLEDGE_MISSING_CONTAINER,
 auditMap, ex));
+      throw ex;
+    }
+  }
+
+  @Override
+  public void unacknowledgeMissingContainer(long longContainerID) throws 
IOException {
+    ContainerID containerID = ContainerID.valueOf(longContainerID);
+    final Map<String, String> auditMap = new HashMap<>();
+    auditMap.put("containerID", containerID.toString());
+
+    try {
+      ContainerInfo containerInfo = 
scm.getContainerManager().getContainer(containerID);

Review Comment:
   t will be better to add admin check here as well like other admin 
operations. You can add a check getScm().checkAdminAccess(getRemoteUser(), 
false);



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -1680,4 +1680,55 @@ public void reconcileContainer(long longContainerID) 
throws IOException {
       throw ex;
     }
   }
+
+  @Override
+  public void acknowledgeMissingContainer(long longContainerID) throws 
IOException {
+    ContainerID containerID = ContainerID.valueOf(longContainerID);
+    final Map<String, String> auditMap = new HashMap<>();
+    auditMap.put("containerID", containerID.toString());
+
+    try {
+      ContainerInfo containerInfo = 
scm.getContainerManager().getContainer(containerID);

Review Comment:
   It will be better to add admin check here as well like other admin 
operations. You can add a check `getScm().checkAdminAccess(getRemoteUser(), 
false);`



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerInfo.java:
##########
@@ -263,6 +266,24 @@ public void setHealthState(ContainerHealthState 
newHealthState) {
     this.healthState = newHealthState;
   }
 
+  /**
+   * Check if container is acked as missing.
+   *
+   * @return boolean
+   */
+  public boolean getAckMissing() {

Review Comment:
   For boolean fields, it's a common Java convention to name getter methods 
with an is prefix (e.g., isAckMissing()) instead of get. Also setter can also 
updated.
   
     ```
   public boolean isAckMissing() {
       return ackMissing;
     }
   
     public void setAckMissing(boolean acked) {
       this.ackMissing = acked;
     }
   ```



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/container/AckMissingSubcommand.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.cli.container;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.scm.cli.ScmSubcommand;
+import org.apache.hadoop.hdds.scm.client.ScmClient;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerListResult;
+import picocli.CommandLine;
+
+/**
+ * Acknowledge missing container(s) to suppress them from Replication Manager 
Report.
+ */
[email protected](
+    name = "ack",
+    description = "Acknowledge missing container(s) to suppress them from 
reports",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class)
+public class AckMissingSubcommand extends ScmSubcommand {
+
+  @CommandLine.Parameters(description = "Container IDs to acknowledge 
(comma-separated)",
+      arity = "0..1")
+  private String containers;
+
+  @CommandLine.Option(names = {"--list"},
+      description = "List all acknowledged missing containers")
+  private boolean list;
+
+  @Override
+  public void execute(ScmClient scmClient) throws IOException {
+    if (list) {
+      // List acknowledged containers
+      ContainerListResult result = scmClient.listContainer(1, 
Integer.MAX_VALUE);

Review Comment:
   Fetching all containers and filtering them on the client side can be 
inefficient if the cluster has a large number of containers. Consider adding a 
server-side filter to listContainer to fetch only the containers with 
ackMissing=true. This would require changes to the 
StorageContainerLocationProtocol.
   
   If it is difficult, I am ok with the current changes  since it is used by 
CLI tool only.



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