imbajin commented on code in PR #3258:
URL: https://github.com/apache/hugegraph/pull/3258#discussion_r4205244724
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh:
##########
@@ -110,30 +120,97 @@ JAVA_VERSION=$($JAVA -version 2>&1 |
# Drop any pre-release suffix, e.g. "24-ea" -> "24"
JAVA_VERSION="${JAVA_VERSION%%[!0-9]*}"
if [[ -z $JAVA_VERSION || $JAVA_VERSION -lt $MIN_JAVA_VERSION ]]; then
- echo "Make sure the JDK is installed and the version >= $MIN_JAVA_VERSION,
current is $JAVA_VERSION" \
- >> "${OUTPUT}"
+ report_error "Make sure the JDK is installed and the version >=
$MIN_JAVA_VERSION, current is $JAVA_VERSION"
exit 1
fi
if [[ ! -r ${JVM_MODULE_OPTIONS} ]]; then
- echo "Missing or unreadable JVM module options file:
${JVM_MODULE_OPTIONS}" >> "${OUTPUT}"
+ report_error "Missing or unreadable JVM module options file:
${JVM_MODULE_OPTIONS}"
exit 1
fi
# Set Java options
if [ "$JAVA_OPTIONS" = "" ]; then
XMX=$(calc_xmx $MIN_MEM $MAX_MEM)
if [ $? -ne 0 ]; then
- echo "Failed to start HugeGraphServer, requires at least ${MIN_MEM}MB
free memory" >> "${OUTPUT}"
+ report_error "Failed to start HugeGraphServer, requires at least
${MIN_MEM}MB free memory"
exit 1
fi
- JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${LOGS} ${USER_OPTION}"
+ JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m ${USER_OPTION}"
# Rolling out detailed GC logs
#JAVA_OPTIONS="${JAVA_OPTIONS} -XX:+UseGCLogFileRotation
-XX:GCLogFileSize=10M -XX:NumberOfGCLogFiles=3 \
# -Xloggc:./logs/gc.log -XX:+PrintHeapAtGC
-XX:+PrintGCDetails -XX:+PrintGCDateStamps"
fi
+# Keep heap dumps and JVM crash logs in $LOGS whatever JAVA_OPTIONS holds. The
+# defaults go first in JAVA_TOOL_OPTIONS, which the JVM reads before the
operator's
+# own JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, the command line (JAVA_OPTIONS and
-j)
+# and _JAVA_OPTIONS, so any of those overrides them. The JVM does that parsing
+# itself, including quoted options and @argfiles.
+# Child JVMs the Server starts (computer jobs, for example) inherit these
options,
+# so every path must stay unique per JVM. ErrorFile expands %p to each JVM's
PID.
+# HeapDumpPath does not expand %p, but when it names an existing directory
each JVM
+# writes java_pid<its pid>.hprof inside it, so it points at a directory per
launch.
+# A restarted container often reuses the PID, and HotSpot will not overwrite an
+# existing crash log or heap dump, so the names carry the host name (the pod
name
+# on Kubernetes, so pods sharing one log volume do not collide), the launch
time,
+# and a counter that skips names already used in $LOGS.
+crash_files_exist() {
+ [[ -e "${LOGS}/heapdump_$1" ]] && return 0
+ local file
+ for file in "${LOGS}"/hs_err_pid*_"$1".log; do
+ [[ -e ${file} ]] && return 0
+ done
+ return 1
+}
+LAUNCH_HOST=$(printf '%s' "${HOSTNAME:-localhost}" | tr -c 'A-Za-z0-9._-' '_')
+# Each launch records the JVM that owns its heap dump directory in a file named
+# pid, a name the license check already skips: the PID and that process's start
+# time, so a reused PID (common after a container restart) does not look like
the
+# old owner. A live JVM's directory stays empty until it runs out of memory, so
+# startup removes a directory only when it holds nothing but that file and that
+# exact process is gone. Directories without a marker, with a dump, or owned
by a
+# running process are left alone, and nothing is removed when ps cannot tell.
+process_identity() {
+ # Collapse ps's padding so the value reads back unchanged from pid.
+ ps -o lstart= -p "$1" 2>/dev/null | awk '{$1 = $1; print}'
+}
+remove_unused_heap_dump_dir() {
+ local dir="$1" owner_pid="" owner_start="" entries
+ [[ -f "${dir}/pid" ]] || return 0
+ entries=$(ls -A "${dir}")
+ [[ ${entries} == "pid" ]] || return 0
+ { read -r owner_pid; read -r owner_start; } < "${dir}/pid"
+ [[ -n ${owner_pid} && -n ${owner_start} ]] || return 0
+ [[ $(process_identity "${owner_pid}") == "${owner_start}" ]] && return 0
Review Comment:
⚠️ Blocking: no. Summary: This cleanup checks only the Server JVM PID, but
computer-job children inherit the same HeapDumpPath. If the Server exits while
a child remains alive, the next start can remove the child's still-empty dump
directory and its later OOM dump will fail; please retain the directory until
all JVMs using it have exited. Evidence: exact-head
hugegraph-server.sh:151-154, 181-187; AbstractComputer.java:107-123 starts
hadoop without replacing its environment or terminating it when the Server
exits.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]