Skip to content

Commit c3b2303

Browse files
pauloricardomgsmiklosovic
authored andcommitted
Heap dump should not be generated on handled exceptions
Patch by Paulo Motta; Reviewed by Isaac Reath, Stefan Miklosovic for CASSANDRA-20974
1 parent a36b1f1 commit c3b2303

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
5.0.7
2+
* Heap dump should not be generated on handled exceptions (CASSANDRA-20974)
23
Merged from 4.1:
3-
* ReadCommandController should close fast to avoid deadlock when building secondary index (CASSANDRA-19564)
4+
* ReadCommandController should close fast to avoid deadlock when building secondary index (CASSANDRA-19564)
45
Merged from 4.0:
56
* Updated dtest-api to 0.0.18 and removed JMX-related classes that now live in the dtest-api (CASSANDRA-20884)
67

src/java/org/apache/cassandra/utils/HeapUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ public static String maybeCreateHeapDump()
128128

129129
return fullPath;
130130
}
131-
else
132-
{
133-
logger.debug("Heap dump creation on uncaught exceptions is disabled.");
134-
}
135131
}
136132
catch (Throwable e)
137133
{

src/java/org/apache/cassandra/utils/JVMStabilityInspector.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void uncaughtException(Thread thread, Throwable t)
7575
if (t2 != t && (t2 instanceof FSError || t2 instanceof CorruptSSTableException))
7676
logger.error("Exception in thread {}", thread, t2);
7777
}
78-
JVMStabilityInspector.inspectThrowable(t);
78+
inspectThrowable(t, JVMStabilityInspector::inspectDiskError, true);
7979
}
8080

8181
/**
@@ -86,12 +86,12 @@ public static void uncaughtException(Thread thread, Throwable t)
8686
*/
8787
public static void inspectThrowable(Throwable t) throws OutOfMemoryError
8888
{
89-
inspectThrowable(t, JVMStabilityInspector::inspectDiskError);
89+
inspectThrowable(t, JVMStabilityInspector::inspectDiskError, false);
9090
}
9191

9292
public static void inspectCommitLogThrowable(Throwable t)
9393
{
94-
inspectThrowable(t, JVMStabilityInspector::inspectCommitLogError);
94+
inspectThrowable(t, JVMStabilityInspector::inspectCommitLogError, false);
9595
}
9696

9797
private static void inspectDiskError(Throwable t)
@@ -102,7 +102,7 @@ else if (t instanceof FSError)
102102
FileUtils.handleFSError((FSError) t);
103103
}
104104

105-
public static void inspectThrowable(Throwable t, Consumer<Throwable> fn) throws OutOfMemoryError
105+
public static void inspectThrowable(Throwable t, Consumer<Throwable> fn, boolean isUncaughtException) throws OutOfMemoryError
106106
{
107107
boolean isUnstable = false;
108108
if (t instanceof OutOfMemoryError)
@@ -136,7 +136,18 @@ else if (t instanceof UnrecoverableIllegalStateException)
136136
}
137137

138138
// Anything other than an OOM, we should try and heap dump to capture what's going on if configured to do so
139-
HeapUtils.maybeCreateHeapDump();
139+
if (isUncaughtException && DatabaseDescriptor.getDumpHeapOnUncaughtException())
140+
{
141+
try
142+
{
143+
// Avoid entering maybeCreateHeapDump unless the setting is enabled to avoid expensive lock
144+
HeapUtils.maybeCreateHeapDump();
145+
}
146+
catch (Throwable sub)
147+
{
148+
t.addSuppressed(sub);
149+
}
150+
}
140151

141152
if (t instanceof InterruptedException)
142153
throw new UncheckedInterruptedException((InterruptedException) t);
@@ -167,7 +178,7 @@ else if (t instanceof UnrecoverableIllegalStateException)
167178
}
168179

169180
if (t.getCause() != null)
170-
inspectThrowable(t.getCause(), fn);
181+
inspectThrowable(t.getCause(), fn, isUncaughtException);
171182
}
172183

173184
private static final Set<String> FORCE_HEAP_OOM_IGNORE_SET = ImmutableSet.of("Java heap space", "GC Overhead limit exceeded");

0 commit comments

Comments
 (0)