From 07777feca350c1fd7f5bc85f024669a67f5ebcbc Mon Sep 17 00:00:00 2001 From: kongxinghan Date: Wed, 14 May 2025 21:17:39 +0800 Subject: [PATCH 1/2] modify shell script --- tools/parse_parameter/parse_para.sh | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/parse_parameter/parse_para.sh b/tools/parse_parameter/parse_para.sh index 7cd1b0875..61ea91b88 100644 --- a/tools/parse_parameter/parse_para.sh +++ b/tools/parse_parameter/parse_para.sh @@ -22,21 +22,21 @@ if [[ "$use_config_file" == "false" ]]; then value="${BASH_REMATCH[1]}" value=${value//\\/} if [[ "$value" != "true" ]]; then - echo "$input" + printf "%s\n" "$input" exit 0 fi else - echo "$input" + printf "%s\n" "$input" exit 0 fi # 检查堆外内存配置是否开启 if [[ "$input" =~ --conf[[:space:]]+spark.memory.offHeap.enabled=([^[:space:]]+) ]]; then - value="${BASH_REMATCH[1]}" + value=$(printf "%s\n" "$input" | grep -oP '.*\K--conf[[:space:]]+spark\.memory\.offHeap\.enabled=\K[^[:space:]]+') value=${value//\\/} # 如果堆外内存开启,则不能借用堆内内存 if [[ "$value" == "true" ]]; then - echo "$input" + printf "%s\n" "$input" exit 0 fi fi @@ -49,11 +49,11 @@ if [[ "$use_config_file" == "false" ]]; then if [[ "$value" =~ ^[0-9]+$ ]]; then memFraction=$value if (($(awk 'BEGIN{print ('$memFraction' > 100) ? 1 : 0}'))); then - echo "$input" + printf "%s\n" "$input" exit 0 fi else - echo "$input" + printf "%s\n" "$input" exit 0 fi fi @@ -61,22 +61,22 @@ elif [[ "$use_config_file" == "true" ]]; then # 判断配置文件中是否开启内存借用 value=$(awk '$1=="spark.omni.enableBorrow"{print $2}' "$config_file_path") if [ -z "$value" ]; then - echo "$input" + printf "%s\n" "$input" exit 0 else if [ "$value" != "true" ]; then - echo "$input" + printf "%s\n" "$input" exit 0 fi fi # 检查输入参数中堆外内存配置是否开启 if [[ "$input" =~ --conf[[:space:]]+spark.memory.offHeap.enabled=([^[:space:]]+) ]]; then - value="${BASH_REMATCH[1]}" + value=$(printf "%s\n" "$input" | grep -oP '.*\K--conf[[:space:]]+spark\.memory\.offHeap\.enabled=\K[^[:space:]]+') value=${value//\\/} # 如果堆外内存开启,则不能借用堆内内存 if [[ "$value" == "true" ]]; then - echo "$input" + printf "%s\n" "$input" exit 0 fi fi @@ -84,7 +84,7 @@ elif [[ "$use_config_file" == "true" ]]; then value=$(awk '$1=="spark.memory.offHeap.enabled"{print $2}' "$config_file_path") if [ -n "$value" ]; then if [ "$value" == "true" ]; then - echo "$input" + printf "%s\n" "$input" exit 0 fi fi @@ -96,16 +96,16 @@ elif [[ "$use_config_file" == "true" ]]; then memFraction=$value if (($(awk 'BEGIN{print ('$memFraction' > 100) ? 1 : 0}'))); then # echo "错误:memFraction 不能大于100,当前值为 $memFraction" - echo "$input" + printf "%s\n" "$input" exit 0 fi else - echo "$input" + printf "%s\n" "$input" exit 0 fi fi else - echo "$input" + printf "%s\n" "$input" exit 0 fi @@ -117,14 +117,14 @@ if [[ "$input" =~ --executor-memory[[:space:]]+([0-9]+)[.]?[0-9]*([a-zA-Z]+) ]]; executorMemory=$(awk "BEGIN {print $value - $borrowedMemory}") else - echo "$input" + printf "%s\n" "$input" exit 0 fi # 1. 替换 --executor-memory 为 executorMemory+memoryUnit -output=$(echo "$input" | sed -E "s/(--executor-memory[[:space:]=]+)[^#[:space:]\\]*/\1${executorMemory}${memoryUnit}/") +output=$(printf "%s\n" "$input" | sed -E "s/(--executor-memory[[:space:]=]+)[^#[:space:]\\]*/\1${executorMemory}${memoryUnit}/") # 2. 增加新参数 output="${output} --conf spark.memory.offHeap.enabled=true --conf spark.memory.offHeap.size=${borrowedMemory}${memoryUnit}" -echo "$output" +printf "%s\n" "$output" -- Gitee From 7c44f1f6dc5161134d0a11d905a384e308e138ca Mon Sep 17 00:00:00 2001 From: kongxinghan Date: Sat, 17 May 2025 10:43:48 +0800 Subject: [PATCH 2/2] solve -e problem --- tools/parse_parameter/parse_para.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/parse_parameter/parse_para.sh b/tools/parse_parameter/parse_para.sh index 61ea91b88..64081aa18 100644 --- a/tools/parse_parameter/parse_para.sh +++ b/tools/parse_parameter/parse_para.sh @@ -14,6 +14,13 @@ use_config_file="false" # conf文件路径 config_file_path="/usr/local/spark/conf/spark-defaults.conf" +for arg in "$@"; do + + if [[ "$arg" == "-e" ]]; then + exit 2 + fi + +done # 如果没有使用conf文件配置参数,直接在参数中读取 if [[ "$use_config_file" == "false" ]]; then -- Gitee