Limit the number of held heap dumps to not consume disk space excessively

patch by Igor Kamyshnikov; reviewed by Dmitry Konstantinov, Stefan Miklosovic for CASSANDRA-20457
This commit is contained in:
Igor Kamyshnikov 2025-05-19 22:32:17 +01:00 committed by Stefan Miklosovic
parent 0a7797ca85
commit 7bf6eef9d4
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 30 additions and 0 deletions

View File

@ -1,4 +1,5 @@
5.1 5.1
* Limit the number of held heap dumps to not consume disk space excessively (CASSANDRA-20457)
* Accord: BEGIN TRANSACTIONs IF condition logic does not properly support meaningless emptiness and null values (CASSANDRA-20667) * Accord: BEGIN TRANSACTIONs IF condition logic does not properly support meaningless emptiness and null values (CASSANDRA-20667)
* Accord: startup race condition where accord journal tries to access the 2i index before its ready (CASSANDRA-20686) * Accord: startup race condition where accord journal tries to access the 2i index before its ready (CASSANDRA-20686)
* Adopt Unsafe::invokeCleaner for Direct ByteBuffer cleaning (CASSANDRA-20677) * Adopt Unsafe::invokeCleaner for Direct ByteBuffer cleaning (CASSANDRA-20677)

View File

@ -174,6 +174,23 @@ case "`uname -s`" in
;; ;;
esac esac
clean_heap_dump_files()
{
if [ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" != "" ] && \
[ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" -ge 0 ] && \
[ -d "$CASSANDRA_HEAPDUMP_DIR" ]; then
# find all files under CASSANDRA_HEAPDUMP_DIR,
# sort by last modification date descending,
# print those, that need to be removed
ls -pt1 "$CASSANDRA_HEAPDUMP_DIR" | grep -v / | \
grep "^cassandra-.*-pid.*[.]hprof$" | \
awk "{ if (NR > $CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES) print \$0}" | \
while IFS= read -r file; do
rm -f "$CASSANDRA_HEAPDUMP_DIR/$file"
done
fi
}
launch_service() launch_service()
{ {
pidpath="$1" pidpath="$1"
@ -188,6 +205,8 @@ launch_service()
cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath" cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath"
fi fi
clean_heap_dump_files
# The cassandra-foreground option will tell CassandraDaemon not # The cassandra-foreground option will tell CassandraDaemon not
# to close stdout/stderr, but it's up to us not to background. # to close stdout/stderr, but it's up to us not to background.
if [ "x$foreground" != "x" ]; then if [ "x$foreground" != "x" ]; then
@ -247,6 +266,8 @@ while true; do
;; ;;
-H) -H)
properties="$properties -XX:HeapDumpPath=$2" properties="$properties -XX:HeapDumpPath=$2"
# disable automatic heap dump files management as HeapDumpPath was overridden
CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES=-1
shift 2 shift 2
;; ;;
-E) -E)

View File

@ -199,6 +199,14 @@ if [ "x$CASSANDRA_HEAPDUMP_DIR" = "x" ]; then
fi fi
JVM_OPTS="$JVM_OPTS -XX:HeapDumpPath=$CASSANDRA_HEAPDUMP_DIR/cassandra-`date +%s`-pid$$.hprof" JVM_OPTS="$JVM_OPTS -XX:HeapDumpPath=$CASSANDRA_HEAPDUMP_DIR/cassandra-`date +%s`-pid$$.hprof"
# Cassandra heap dump files management options:
# N >= 0 - keep N newest files
# -1 - disable clean up
# defaults to 2 if not set
if [ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" = "" ]; then
CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES=2
fi
# stop the jvm on OutOfMemoryError as it can result in some data corruption # stop the jvm on OutOfMemoryError as it can result in some data corruption
# uncomment the preferred option # uncomment the preferred option
# ExitOnOutOfMemoryError and CrashOnOutOfMemoryError require a JRE greater or equals to 1.7 update 101 or 1.8 update 92 # ExitOnOutOfMemoryError and CrashOnOutOfMemoryError require a JRE greater or equals to 1.7 update 101 or 1.8 update 92