smengcl commented on code in PR #9155:
URL: https://github.com/apache/ozone/pull/9155#discussion_r2483162940


##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/TriggerSnapshotDefragSubCommand.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.admin.om;
+
+import java.util.concurrent.Callable;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import picocli.CommandLine;
+
+/**
+ * Handler of ozone admin om triggerSnapshotDefrag command.
+ */
[email protected](
+    name = "triggerSnapshotDefrag",
+    description = "Triggers the Snapshot Defragmentation Service to run " +
+        "immediately. This command manually initiates the snapshot " +
+        "defragmentation process which compacts snapshot data and removes " +
+        "fragmentation to improve storage efficiency.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+public class TriggerSnapshotDefragSubCommand implements Callable<Void> {
+
+  @CommandLine.ParentCommand
+  private OMAdmin parent;
+
+  @CommandLine.Option(
+      names = {"-id", "--service-id"},
+      description = "Ozone Manager Service ID"
+  )
+  private String omServiceId;
+
+  @CommandLine.Option(
+      names = {"-host", "--service-host"},
+      description = "Ozone Manager Host"
+  )
+  private String omHost;
+
+  @CommandLine.Option(
+      names = {"--no-wait"},
+      description = "Do not wait for the defragmentation task to complete. " +
+          "The command will return immediately after triggering the task.",
+      defaultValue = "false"
+  )
+  private boolean noWait;
+
+  @Override
+  public Void call() throws Exception {
+    boolean forceHA = false;
+
+    try (OzoneManagerProtocol client = parent.createOmClient(omServiceId, 
omHost, forceHA)) {

Review Comment:
   done



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -3554,6 +3554,53 @@ public boolean triggerRangerBGSync(boolean noWait) 
throws IOException {
     }
   }
 
+  @Override
+  public boolean triggerSnapshotDefrag(boolean noWait) throws IOException {
+
+    // OM should be leader and ready.
+    if (!isLeaderReady()) {
+      throw new OMException("OM is not leader or not ready", INVALID_REQUEST);

Review Comment:
   done



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