Repository: spark
Updated Branches:
  refs/heads/master 669e3f058 -> 92ca910eb


[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 <timhun...@databricks.com>

Closes #1674 from thunterdb/closure_issue and squashes the following commits:

e1e664d [Timothy Hunter] simplify closure


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/92ca910e
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/92ca910e
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/92ca910e

Branch: refs/heads/master
Commit: 92ca910eb866701e01b987a4f5003564b4785959
Parents: 669e3f0
Author: Timothy Hunter <timhun...@databricks.com>
Authored: Thu Jul 31 10:25:40 2014 -0700
Committer: Matei Zaharia <ma...@databricks.com>
Committed: Thu Jul 31 10:25:40 2014 -0700

----------------------------------------------------------------------
 .../org/apache/spark/repl/SparkILoop.scala      | 39 ++++++++++----------
 1 file changed, 20 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/92ca910e/repl/src/main/scala/org/apache/spark/repl/SparkILoop.scala
----------------------------------------------------------------------
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 e1db4d5..6f9fa0d 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()

Reply via email to