Skip to content
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

HDDS-11727. Block ozone repair when a node is running #7589

Merged
merged 3 commits into from
Jan 3, 2025
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
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
Loading