Skip to content

[SPARK-24243][CORE] Expose exceptions from InProcessAppHandle #21849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

sahilTakiar
Copy link

What changes were proposed in this pull request?

Adds a new method to SparkAppHandle called getError which returns
the exception (if present) that caused the underlying Spark app to
fail.

How was this patch tested?

New tests added to SparkLauncherSuite for the new method.

@sahilTakiar
Copy link
Author

@vanzin could you take a look? I'm not sure if the same race conditions present in the other unit tests apply to the new ones since no SparkContext is being created. For now I didn't add any synchronization, but I can add some.


assertNotNull(handle.getError());
assertTrue(handle.getError().isPresent());
assertTrue(handle.getError().get().getCause() == DUMMY_EXCEPTION);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertSame? (Although it's slightly weird to have a static exception instance being thrown.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to assertSame

@@ -46,6 +47,18 @@ public synchronized void disconnect() {
}
}

/**
* Since {@link SparkLauncher} runs {@code spark-submit} in a sub-process, its difficult to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a public API, good to follow standard javadoc practices like the first sentence being a short description of the method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the javadocs

* accurately retrieve the full {@link Throwable} from the {@code spark-submit} process. This
* method parses the logs of the sub-process and provides a best-effort attempt at returning
* the last exception thrown by the {@code spark-submit} process. Only the exception message is
* parsed, the associated stack-trace is meaningless.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lose the dash

@@ -63,6 +71,7 @@ synchronized void start(String appName, Method main, String[] args) {
main.invoke(null, (Object) args);
} catch (Throwable t) {
LOG.log(Level.WARNING, "Application failed with exception.", t);
error = t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to special-case InvocationTargetException and avoid one level of wrapping which is probably not useful to anyone.

@@ -17,6 +17,8 @@

package org.apache.spark.launcher;

import org.apache.commons.lang.StringUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module shouldn't really depend on any 3rd-party libraries... there's an oddity in the current parent pom that causes this dependency to be available but I think we should instead fix that by adding this property to launcher/pom.xml:

    <hadoop.deps.scope>test</hadoop.deps.scope>

containsIgnoreCase shouldn't really be hard to replicate. Although, if you really want to simplify things, I'd just set the error in this case to a generic "Spark exited with error code X. Please check logs.".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied the code into a helper method

@vanzin
Copy link
Contributor

vanzin commented Aug 14, 2018

ok to test

@SparkQA
Copy link

SparkQA commented Aug 14, 2018

Test build #94772 has finished for PR 21849 at commit 7e3100e.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sahilTakiar
Copy link
Author

@vanzin addressed your comments and updated the PR

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95481 has finished for PR 21849 at commit d5d51d2.

  • This patch fails MiMa tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Aug 30, 2018

It's safe to add a mima exception for that error since SparkAppHandle is not meant to be implemented by external code. So it's safe to add methods to it.

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95488 has finished for PR 21849 at commit a8bbd67.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Adds a new method to `SparkAppHandle` called `getError` which returns
the exception (if present) that caused the underlying Spark app to
fail.

New tests added to `SparkLauncherSuite` for the new method.
@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95489 has finished for PR 21849 at commit 9240b77.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@vanzin vanzin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just small things.

* Parses the logs of {@code spark-submit} and returns the last exception thrown.
*
* <p>
* Since {@link SparkLauncher} runs {@code spark-submit} in a sub-process, its difficult to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's

also, small nit: keep the text at the same indent level as the p tags (as is done in other classes).

ProblemFilters.exclude[MissingClassProblem]("org.apache.spark.ml.classification.LabelConverter"),

// [SPARK-24243][CORE] Expose exceptions from InProcessAppHandle
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.launcher.SparkAppHandle.getError")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add at the top of the list (then you don't have to touch existing entries).

handle.kill();
}
restoreSystemProperties(properties);
waitForSparkContextShutdown();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really necessary since ErrorInProcessTestApp does not create a context; but not a big deal either.

@@ -61,6 +62,10 @@ private void redirect() {
while ((line = reader.readLine()) != null) {
if (active) {
sink.info(line.replaceFirst("\\s*$", ""));
if (error == null && containsIgnoreCase(line, "Error") || containsIgnoreCase(line,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: group the conditions so people don't have to remember how precedence work. Also it looks better if you keep the whole call to containsIgnoreCase in the same line.

Wouldn't you want to keep the last error, though, instead of the first one?

@asfgit asfgit closed this in 543577a Dec 7, 2018
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
Adds a new method to SparkAppHandle called getError which returns
the exception (if present) that caused the underlying Spark app to
fail.

New tests added to SparkLauncherSuite for the new method.

Closes apache#21849

Closes apache#23221 from vanzin/SPARK-24243.

Signed-off-by: Marcelo Vanzin <vanzin@cloudera.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants