From 82ba6edaafb0c9e625e54e42c6449fbaa912e234 Mon Sep 17 00:00:00 2001 From: sarvekshayr Date: Wed, 18 Dec 2024 09:31:00 +0530 Subject: [PATCH] HDDS-11727. Block when a node is running --- hadoop-ozone/dist/src/shell/ozone/ozone | 23 ++++++++++++++++++ .../hadoop/ozone/repair/om/FSORepairCLI.java | 24 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/hadoop-ozone/dist/src/shell/ozone/ozone b/hadoop-ozone/dist/src/shell/ozone/ozone index 0d005b3bd78..eb95ed2b290 100755 --- a/hadoop-ozone/dist/src/shell/ozone/ozone +++ b/hadoop-ozone/dist/src/shell/ozone/ozone @@ -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" @@ -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 diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairCLI.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairCLI.java index 5a217e9f2de..69ea0bdf2aa 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairCLI.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairCLI.java @@ -54,8 +54,16 @@ public class FSORepairCLI implements Callable { 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 { @@ -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; + } }