Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions hadoop-hdds/docs/content/tools/Admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,49 @@ $ ozone admin om lof --service-id=om-service-test1 --length=3 --prefix=/volumelo
```

Note in JSON output mode, field `contToken` won't show up at all in the result if there are no more entries after the batch (i.e. when `hasMore` is `false`).


## Snapshot Defragmentation Trigger

The snapshot defrag command triggers the Snapshot Defragmentation Service to run immediately on a specific Ozone Manager node.
This command manually initiates the snapshot defragmentation process which compacts snapshot data and removes fragmentation to improve storage efficiency.

This command only works on Ozone Manager HA clusters.

```bash
$ ozone admin om snapshot defrag --help
Usage: ozone admin om snapshot defrag [-hV] [--no-wait] [--node-id=<nodeId>]
[-id=<omServiceId>]
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.
-h, --help Show this help message and exit.
--no-wait Do not wait for the defragmentation task to
complete. The command will return immediately
after triggering the task.
--node-id=<nodeId> NodeID of the OM to trigger snapshot
defragmentation on.
-id, --service-id=<omServiceId>
Ozone Manager Service ID
-V, --version Print version information and exit.
```

### Example usages

- Trigger snapshot defragmentation on OM node `om3` in service `omservice` and wait for completion:

```bash
$ ozone admin om snapshot defrag --service-id=omservice --node-id=om3
Triggering Snapshot Defrag Service ...
Snapshot defragmentation completed successfully.
```

- Trigger snapshot defragmentation without waiting for completion:

```bash
$ ozone admin om snapshot defrag --service-id=omservice --node-id=om3 --no-wait
Triggering Snapshot Defrag Service ...
Snapshot defragmentation task has been triggered successfully and is running in the background.
```

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.admin.OzoneAdmin;
import org.apache.hadoop.ozone.admin.om.lease.LeaseSubCommand;
import org.apache.hadoop.ozone.admin.om.snapshot.SnapshotSubCommand;
import org.apache.hadoop.ozone.client.OzoneClientException;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
Expand Down Expand Up @@ -59,7 +60,8 @@
UpdateRangerSubcommand.class,
TransferOmLeaderSubCommand.class,
FetchKeySubCommand.class,
LeaseSubCommand.class
LeaseSubCommand.class,
SnapshotSubCommand.class
})
@MetaInfServices(AdminSubcommand.class)
public class OMAdmin implements AdminSubcommand {
Expand Down
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

)
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();
}
}
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;
}
}
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;
Loading