-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-13640. Add CLI that allows manually triggering snapshot defrag #9155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2fb6999
HDDS-13640. Add CLI that allows manually triggering snapshot defrag
smengcl 4d9e2be
[split] Implement manual trigger of snapshot defrag. e.g. `ozone admi…
smengcl 1fa3a51
Fix https://github.com/apache/ozone/pull/9155/files/4d9e2be4244de8c12…
smengcl 3adeda1
Address Copilot comment
smengcl 4e073e6
Use `triggerSnapshotDefragOnce()` instead of `start()` for the trigger.
smengcl 8cc5e0c
Merge remote-tracking branch 'asf' into HDDS-13640-trigger
smengcl 34bb577
Add test
smengcl 4049698
Use OMAdminProtocolClientSideImpl instead of OzoneManagerProtocol.
smengcl 19781e6
Fix test NPE
smengcl 6ebd996
cleanup
smengcl b2dc0ac
Move CLI: `ozone admin om triggerSnapshotDefrag` to `ozone admin om s…
smengcl 825c85a
Add null check for omNodeDetails; add integration test.
smengcl 288ca78
add doc in Admin.md
smengcl 924a491
checkstyle
smengcl 4cad81b
Remove OzoneManagerProtocol changes that are no longer necessary.
smengcl ec49473
Fix UT
smengcl a56106c
address copilot comments
smengcl f2e9dbd
findbugs
smengcl 6479b01
Update hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/…
smengcl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...e/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/snapshot/DefragSubCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * 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.snapshot; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.Callable; | ||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.admin.om.OMAdmin; | ||
| import org.apache.hadoop.ozone.om.helpers.OMNodeDetails; | ||
| import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolClientSideImpl; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import picocli.CommandLine; | ||
|
|
||
| /** | ||
| * Handler of ozone admin om snapshot defrag command. | ||
| */ | ||
| @CommandLine.Command( | ||
| name = "defrag", | ||
| 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. " + | ||
| "This command works only on OzoneManager HA cluster.", | ||
| mixinStandardHelpOptions = true, | ||
| versionProvider = HddsVersionProvider.class | ||
| ) | ||
| public class DefragSubCommand implements Callable<Void> { | ||
|
|
||
| @CommandLine.ParentCommand | ||
| private SnapshotSubCommand parent; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"-id", "--service-id"}, | ||
| description = "Ozone Manager Service ID" | ||
| ) | ||
| private String omServiceId; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"--node-id"}, | ||
| description = "NodeID of the OM to trigger snapshot defragmentation on.", | ||
| required = false | ||
| ) | ||
| private String nodeId; | ||
|
|
||
| @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 { | ||
| // Navigate up to get OMAdmin | ||
| OMAdmin omAdmin = getOMAdmin(); | ||
| OzoneConfiguration conf = omAdmin.getParent().getOzoneConf(); | ||
| OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf( | ||
| conf, omServiceId, nodeId); | ||
|
|
||
| if (omNodeDetails == null) { | ||
| System.err.println("Error: OMNodeDetails could not be determined with given " + | ||
| "service ID and node ID."); | ||
| return null; | ||
| } | ||
|
|
||
| try (OMAdminProtocolClientSideImpl omAdminProtocolClient = createClient(conf, omNodeDetails)) { | ||
| execute(omAdminProtocolClient); | ||
| } catch (IOException ex) { | ||
| System.err.println("Failed to trigger snapshot defragmentation: " + | ||
| ex.getMessage()); | ||
| throw ex; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| protected OMAdminProtocolClientSideImpl createClient( | ||
| OzoneConfiguration conf, OMNodeDetails omNodeDetails) throws IOException { | ||
| return OMAdminProtocolClientSideImpl.createProxyForSingleOM(conf, | ||
| UserGroupInformation.getCurrentUser(), omNodeDetails); | ||
| } | ||
|
|
||
| protected void execute(OMAdminProtocolClientSideImpl omAdminProtocolClient) | ||
| throws IOException { | ||
| System.out.println("Triggering Snapshot Defrag Service ..."); | ||
| boolean result = omAdminProtocolClient.triggerSnapshotDefrag(noWait); | ||
|
|
||
| if (noWait) { | ||
| System.out.println("Snapshot defragmentation task has been triggered " + | ||
| "successfully and is running in the background."); | ||
| } else { | ||
| if (result) { | ||
| System.out.println("Snapshot defragmentation completed successfully."); | ||
| } else { | ||
| System.out.println("Snapshot defragmentation task failed or was interrupted."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private OMAdmin getOMAdmin() { | ||
| // The parent hierarchy is: DefragSubCommand -> SnapshotSubCommand -> OMAdmin | ||
| return parent.getParent(); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/snapshot/SnapshotSubCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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.snapshot; | ||
|
|
||
| import org.apache.hadoop.ozone.admin.om.OMAdmin; | ||
| import picocli.CommandLine; | ||
|
|
||
| /** | ||
| * Handler of ozone admin om snapshot command. | ||
| */ | ||
| @CommandLine.Command( | ||
| name = "snapshot", | ||
| description = "Command for all snapshot related operations.", | ||
| subcommands = { | ||
| DefragSubCommand.class | ||
| } | ||
| ) | ||
| public class SnapshotSubCommand { | ||
|
|
||
| @CommandLine.ParentCommand | ||
| private OMAdmin parent; | ||
|
|
||
| public OMAdmin getParent() { | ||
| return parent; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/snapshot/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Command line for Ozone Manager snapshot operations. | ||
| */ | ||
| package org.apache.hadoop.ozone.admin.om.snapshot; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not required, which OM node is going to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be specified, with the current framework of how OMNodeDetails is retrieved. It won't select OM leader as I initially expected. So I added that null check.