Skip to content

Commit 7bf6eef

Browse files
gowasmiklosovic
authored andcommitted
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
1 parent 0a7797c commit 7bf6eef

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGES.txt

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

bin/cassandra

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ case "`uname -s`" in
174174
;;
175175
esac
176176

177+
clean_heap_dump_files()
178+
{
179+
if [ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" != "" ] && \
180+
[ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" -ge 0 ] && \
181+
[ -d "$CASSANDRA_HEAPDUMP_DIR" ]; then
182+
# find all files under CASSANDRA_HEAPDUMP_DIR,
183+
# sort by last modification date descending,
184+
# print those, that need to be removed
185+
ls -pt1 "$CASSANDRA_HEAPDUMP_DIR" | grep -v / | \
186+
grep "^cassandra-.*-pid.*[.]hprof$" | \
187+
awk "{ if (NR > $CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES) print \$0}" | \
188+
while IFS= read -r file; do
189+
rm -f "$CASSANDRA_HEAPDUMP_DIR/$file"
190+
done
191+
fi
192+
}
193+
177194
launch_service()
178195
{
179196
pidpath="$1"
@@ -188,6 +205,8 @@ launch_service()
188205
cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath"
189206
fi
190207

208+
clean_heap_dump_files
209+
191210
# The cassandra-foreground option will tell CassandraDaemon not
192211
# to close stdout/stderr, but it's up to us not to background.
193212
if [ "x$foreground" != "x" ]; then
@@ -247,6 +266,8 @@ while true; do
247266
;;
248267
-H)
249268
properties="$properties -XX:HeapDumpPath=$2"
269+
# disable automatic heap dump files management as HeapDumpPath was overridden
270+
CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES=-1
250271
shift 2
251272
;;
252273
-E)

conf/cassandra-env.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ if [ "x$CASSANDRA_HEAPDUMP_DIR" = "x" ]; then
199199
fi
200200
JVM_OPTS="$JVM_OPTS -XX:HeapDumpPath=$CASSANDRA_HEAPDUMP_DIR/cassandra-`date +%s`-pid$$.hprof"
201201

202+
# Cassandra heap dump files management options:
203+
# N >= 0 - keep N newest files
204+
# -1 - disable clean up
205+
# defaults to 2 if not set
206+
if [ "$CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES" = "" ]; then
207+
CASSANDRA_HEAPDUMP_KEEP_NEWEST_N_FILES=2
208+
fi
209+
202210
# stop the jvm on OutOfMemoryError as it can result in some data corruption
203211
# uncomment the preferred option
204212
# ExitOnOutOfMemoryError and CrashOnOutOfMemoryError require a JRE greater or equals to 1.7 update 101 or 1.8 update 92

0 commit comments

Comments
 (0)