Skip to content

Commit

Permalink
HDDS-11727. Block when a node is running
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvekshayr committed Dec 18, 2024
1 parent befd64e commit 82ba6ed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
23 changes: 23 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,28 @@ 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")
local running_services=()

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
running_services+=("${service}")
fi
fi
done
done

export OZONE_RUNNING_SERVICES="${running_services[*]}"
}

## @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 @@ -54,8 +54,16 @@ public class FSORepairCLI implements Callable<Void> {
description = "Verbose output. Show all intermediate steps and deleted keys info.")
private boolean verbose;

@CommandLine.Option(names = {"--force"},
description = "Use --force flag only in false-positive cases."
)
private boolean force;

@Override
public Void call() throws Exception {
if (checkIfOMIsRunning()) {
return null;
}
if (repair) {
System.out.println("FSO Repair Tool is running in repair mode");
} else {
Expand All @@ -75,4 +83,20 @@ public Void call() throws Exception {

return null;
}

private boolean checkIfOMIsRunning() {
String runningServices = System.getenv("OZONE_RUNNING_SERVICES");
if (runningServices != null && runningServices.contains("om")) {
if (!force) {
System.err.println("Error: OM is currently running on this host. " +
"Stop the OM service before running the repair tool.");
return true;
} else {
System.out.println("Warning: --force flag used. Proceeding despite OM being detected as running.");
}
} else {
System.out.println("No running OM service detected. Proceeding with repair.");
}
return false;
}
}

0 comments on commit 82ba6ed

Please sign in to comment.