ctubbsii commented on code in PR #5439:
URL: https://github.com/apache/accumulo/pull/5439#discussion_r2034159238


##########
assemble/bin/accumulo-cluster:
##########
@@ -646,12 +651,171 @@ function control_services() {
   if [[ $ARG_LOCAL == 0 && $ARG_ALL == 1 && ($operation == "stop" || 
$operation == "kill") ]]; then
     if ! isDebug; then
       echo "Cleaning all server entries in ZooKeeper"
-      "$accumulo_cmd" org.apache.accumulo.server.util.ZooZap -manager 
-tservers -compaction-coordinators -compactors -sservers
+      "$accumulo_cmd" org.apache.accumulo.server.util.ZooZap -manager 
-tservers -compaction-coordinators -compactors -sservers --gc --monitor
     fi
   fi
 
 }
 
+function prune_group() {
+  local service_type=$1
+  local group=$2
+  local expectedCount=$3
+  declare -a hosts
+  read -r -a hosts <<<"$4"
+
+  # TODO remove or make debug
+  echo "$service_type $group $expectedCount"
+
+  if [ -z ${AC_TMP_DIR+x} ]; then
+    echo "AC_TMP_DIR is not set"
+    exit 1
+  fi
+  local 
exclude_file="$AC_TMP_DIR/accumulo-zoozap-exclude-$service_type-$group.txt"
+
+  # Determine the host:ports known by the accumulo cluster script, these 
should be kept
+  for host in "${hosts[@]}"; do
+    #TODO need to ssh
+    "$bin"/accumulo-service "$service_type" list | grep "$group" | tail -n +2 
| awk '{print "'"$host"':" $3}' | head -n "$expectedCount" >>"$exclude_file"
+  done
+
+  # TODO remove or make debug
+  echo "$exclude_file"
+  cat "$exclude_file"
+
+  local lockTypeOpt
+  case $service_type in
+    manager)
+      lockTypeOpt="-manager"
+      ;;
+    compaction-coordinator)
+      lockTypeOpt="-compaction-coordinators"
+      ;;
+    compactor)
+      lockTypeOpt="-compactors"
+      ;;
+    tserver)
+      lockTypeOpt="-tservers"
+      ;;
+    sserver)
+      lockTypeOpt="-sservers"
+      ;;
+    gc)
+      lockTypeOpt="--gc"
+      ;;
+    monitor)
+      lockTypeOpt="--monitor"
+      ;;
+    *)
+      echo "Prune does not support $service_type"
+      exit 1
+      ;;
+  esac
+
+  "$accumulo_cmd" org.apache.accumulo.server.util.ZooZap $lockTypeOpt -verbose 
--include-groups "$group" --exclude-host-ports "$exclude_file"
+}
+
+# Kills extra server processes that are not needed according to the
+# cluster.yaml file.  Conceptually this code is trying to reconcile the
+# following three sets of servers.
+#
+#  1. The notional goal set of servers specified by cluster.yaml
+#  2. The set of servers processes seen in zookeeper
+#  3. The set of server processes known to the accumulo-cluster script.  This
+#     is derived from pid files on hosts in set 1.
+#
+# This function attempts to find extra servers in set 2 that are not specified
+# by set 1.  When it does find extra servers it removes their zookeeper locks
+# avoiding removing locks of servers in set 3. The following are different
+# situations the code will see and handle.
+#
+#  * When a host is not cluster.yaml but has some processes listed in
+#    zookeeper.  For this case all of the process with that host can be killed.
+#  * When a resource group is not in cluster.yaml but has some processes listed
+#    in zookeeper.  For this case all of the processes with that resource group
+#    can be killed.
+#  * When a host is in cluster.yaml with a target of 3 processes but has 6
+#    processes listed in zookeeper.  For this case want to kill 3 processes 
that
+#    do not have pid files on the host.
+#
+function prune() {
+  if [[ $ARG_LOCAL == 1 ]]; then
+    # Currently the code is structured to remove all extra servers in a single 
resource group.  Finer granularity is not supported.
+    echo "Prune does not support running locally"
+    exit 1
+  fi
+
+  if [ -z ${AC_TMP_DIR+x} ]; then

Review Comment:
   Strongly recommend using `[[` instead of `[` to avoid ambiguity between 
bash's built-in language and execution of the external `/usr/bin/[` command.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to