Skip to content
Open
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
2 changes: 1 addition & 1 deletion hadoop-hdds/docs/content/tools/Admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Note in JSON output mode, field `contToken` won't show up at all in the result i
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.
This command only works on Ozone Manager HA clusters. Specify `--node-id` to select which OM to defragment.

```bash
$ ozone admin om snapshot defrag --help
Expand Down
3 changes: 2 additions & 1 deletion hadoop-hdds/docs/content/tools/Repair.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ CLI to get the status of last trigger quota repair if available.

### compact
Compact a column family in the OM DB to clean up tombstones. The compaction happens asynchronously. Requires admin privileges.
OM should be running for this tool.
OM should be running for this tool. On an HA OM cluster, specify `--node-id` to select which OM's db to compact.

```bash
Usage: ozone repair om compact [-hV] [--dry-run] [--force] [--verbose]
--cf=<columnFamilyName> [--node-id=<nodeId>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.hadoop.hdds.cli.AbstractSubcommand;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.admin.om.OmAddressOptions;
import org.apache.hadoop.ozone.om.helpers.OMNodeDetails;
import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolClientSideImpl;
Expand Down Expand Up @@ -64,6 +65,13 @@ public class DefragSubCommand extends AbstractSubcommand implements Callable<Voi
@Override
public Void call() throws Exception {
OzoneConfiguration conf = getOzoneConf();

if (nodeId == null && OmUtils.isServiceIdsDefined(conf)) {
System.err.println("Error: This is an HA OM cluster; specify --node-id "
+ "to select which OM to defragment.");
return null;
}

OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf(
conf, omServiceOption.getServiceID(), nodeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.hadoop.ozone.admin.om.snapshot;

import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -54,11 +57,17 @@ public class TestDefragSubCommand {
*/
private static class TestableDefragSubCommand extends DefragSubCommand {
private final OMAdminProtocolClientSideImpl mockClient;
private final OzoneConfiguration testConf = new OzoneConfiguration();

TestableDefragSubCommand(OMAdminProtocolClientSideImpl mockClient) {
this.mockClient = mockClient;
}

@Override
protected OzoneConfiguration getOzoneConf() {
return testConf;
}

@Override
protected OMAdminProtocolClientSideImpl createClient(
OzoneConfiguration conf, OMNodeDetails omNodeDetails) {
Expand Down Expand Up @@ -141,6 +150,19 @@ public void testTriggerSnapshotDefragWithServiceIdAndNodeId() throws Exception {
assertTrue(output.contains("Snapshot defragmentation completed successfully"));
}

@Test
public void testDefragHAWithoutNodeIdFailsFast() throws Exception {
cmd.testConf.set(OZONE_OM_SERVICE_IDS_KEY, "omservice");

CommandLine c = new CommandLine(cmd);
c.parseArgs();
cmd.call();

verify(omAdminClient, never()).triggerSnapshotDefrag(anyBoolean());
String error = errContent.toString(DEFAULT_ENCODING);
assertTrue(error.contains("specify --node-id"));
}

@Test
public void testTriggerSnapshotDefragWithAllOptions() throws Exception {
// Test with service-id, node-id, and no-wait options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.utils.db.managed.ManagedCompactRangeOptions;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.helpers.OMNodeDetails;
import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolClientSideImpl;
import org.apache.hadoop.ozone.om.service.CompactDBUtil;
Expand Down Expand Up @@ -71,6 +72,13 @@ public class CompactOMDB extends RepairTool {
public void execute() throws Exception {

OzoneConfiguration conf = getOzoneConf();

if (nodeId == null && OmUtils.isServiceIdsDefined(conf)) {
error("This is an HA OM cluster; specify --node-id to select which OM's"
+ " db to compact.");
return;
}

OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf(
conf, omServiceId, nodeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

package org.apache.hadoop.ozone.repair.om;

import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -117,4 +119,14 @@ public void testCompactWhenOMNodeDetailsNotFound() {

assertThat(err.getOutput()).contains("Couldn't determine OM node");
}

@Test
public void testCompactHAWithoutNodeIdFailsFast() throws Exception {
CommandLine cli = new OzoneRepair().getCmd();
cli.execute("-D", OZONE_OM_SERVICE_IDS_KEY + "=omservice",
"om", "compact", "--column-family", COLUMN_FAMILY);

verify(omAdminClient, never()).compactOMDB(any(), anyInt());
assertThat(err.getOutput()).contains("specify --node-id");
}
}