Skip to content

Commit

Permalink
HDDS-11727. Block ozone repair om fso-tree if OM is running (#7589)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvekshayr authored Jan 3, 2025
1 parent 69206e9 commit d013188
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hadoop-ozone/dist/src/shell/ozone/ozone
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function ozonecmd_case
OZONE_RUN_ARTIFACT_NAME="ozone-tools"
;;
repair)
check_running_ozone_services
OZONE_CLASSNAME=org.apache.hadoop.ozone.repair.OzoneRepair
OZONE_DEBUG_OPTS="${OZONE_DEBUG_OPTS} ${RATIS_OPTS} ${OZONE_MODULE_ACCESS_ARGS}"
OZONE_RUN_ARTIFACT_NAME="ozone-tools"
Expand All @@ -245,6 +246,25 @@ function ozonecmd_case
esac
}

## @description Check for running Ozone services using PID files.
## @audience public
function check_running_ozone_services
{
OZONE_PID_DIR="/tmp"

local services=("om" "scm" "datanode")

for service in "${services[@]}"; do
for pid_file in ${OZONE_PID_DIR}/ozone-*-${service}.pid; do
if [[ -f "${pid_file}" ]]; then
if kill -0 "$(cat "${pid_file}")" 2>/dev/null; then
export "OZONE_${service^^}_RUNNING=true"
fi
fi
done
done
}

## @description turn off logging for CLI by default
## @audience private
function ozone_suppress_shell_log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package org.apache.hadoop.ozone.repair;

import org.apache.hadoop.hdds.cli.AbstractSubcommand;
import picocli.CommandLine;

import java.io.PrintWriter;
import java.util.concurrent.Callable;

/** Parent class for all actionable repair commands. */
public abstract class RepairTool extends AbstractSubcommand implements Callable<Void> {

@CommandLine.Option(names = {"--force"},
description = "Use this flag if you want to bypass the check in false-positive cases.")
private boolean force;

/** Hook method for subclasses for performing actual repair task. */
protected abstract void execute() throws Exception;

Expand All @@ -34,6 +39,23 @@ public final Void call() throws Exception {
return null;
}

protected boolean checkIfServiceIsRunning(String serviceName) {
String envVariable = String.format("OZONE_%s_RUNNING", serviceName);
String runningServices = System.getenv(envVariable);
if ("true".equals(runningServices)) {
if (!force) {
error("Error: %s is currently running on this host. " +
"Stop the service before running the repair tool.", serviceName);
return true;
} else {
info("Warning: --force flag used. Proceeding despite %s being detected as running.", serviceName);
}
} else {
info("No running %s service detected. Proceeding with repair.", serviceName);
}
return false;
}

protected void info(String msg, Object... args) {
out().println(formatMessage(msg, args));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class FSORepairCLI extends RepairTool {

@Override
public void execute() throws Exception {
if (checkIfServiceIsRunning("OM")) {
return;
}
if (repair) {
info("FSO Repair Tool is running in repair mode");
} else {
Expand Down

0 comments on commit d013188

Please sign in to comment.