aboutsummaryrefslogtreecommitdiff
path: root/repl/src/main
diff options
context:
space:
mode:
authorTimothy Hunter <timhunter@databricks.com>2014-07-31 10:25:40 -0700
committerMatei Zaharia <matei@databricks.com>2014-07-31 10:25:40 -0700
commit92ca910eb866701e01b987a4f5003564b4785959 (patch)
tree83b82c5406c77dd4f8b5753ea27b834423143ea2 /repl/src/main
parent669e3f05895d9dfa37abf60f60aecebb03988e50 (diff)
downloadspark-92ca910eb866701e01b987a4f5003564b4785959.tar.gz
spark-92ca910eb866701e01b987a4f5003564b4785959.tar.bz2
spark-92ca910eb866701e01b987a4f5003564b4785959.zip
[SPARK-2762] SparkILoop leaks memory in multi-repl configurations
This pull request is a small refactor so that a partial function (hence a closure) is not created. Instead, a regular function is used. The behavior of the code is not changed. Author: Timothy Hunter <timhunter@databricks.com> Closes #1674 from thunterdb/closure_issue and squashes the following commits: e1e664d [Timothy Hunter] simplify closure
Diffstat (limited to 'repl/src/main')
-rw-r--r--repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala39
1 files changed, 20 insertions, 19 deletions
diff --git a/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala b/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
index e1db4d5395..6f9fa0d9f2 100644
--- a/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
+++ b/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
@@ -557,29 +557,27 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
if (isReplPower) powerCommands else Nil
)*/
- val replayQuestionMessage =
+ private val replayQuestionMessage =
"""|That entry seems to have slain the compiler. Shall I replay
|your session? I can re-run each line except the last one.
|[y/n]
""".trim.stripMargin
- private val crashRecovery: PartialFunction[Throwable, Boolean] = {
- case ex: Throwable =>
- echo(intp.global.throwableAsString(ex))
-
- ex match {
- case _: NoSuchMethodError | _: NoClassDefFoundError =>
- echo("\nUnrecoverable error.")
- throw ex
- case _ =>
- def fn(): Boolean =
- try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
- catch { case _: RuntimeException => false }
-
- if (fn()) replay()
- else echo("\nAbandoning crashed session.")
- }
- true
+ private def crashRecovery(ex: Throwable): Boolean = {
+ echo(ex.toString)
+ ex match {
+ case _: NoSuchMethodError | _: NoClassDefFoundError =>
+ echo("\nUnrecoverable error.")
+ throw ex
+ case _ =>
+ def fn(): Boolean =
+ try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
+ catch { case _: RuntimeException => false }
+
+ if (fn()) replay()
+ else echo("\nAbandoning crashed session.")
+ }
+ true
}
/** The main read-eval-print loop for the repl. It calls
@@ -605,7 +603,10 @@ class SparkILoop(in0: Option[BufferedReader], protected val out: JPrintWriter,
}
}
def innerLoop() {
- if ( try processLine(readOneLine()) catch crashRecovery )
+ val shouldContinue = try {
+ processLine(readOneLine())
+ } catch {case t: Throwable => crashRecovery(t)}
+ if (shouldContinue)
innerLoop()
}
innerLoop()