Skip to content
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

[SPARK-7862][SQL]Fix the deadlock in script transformation for stderr #6404

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.hive.execution

import java.io.{BufferedReader, DataInputStream, DataOutputStream, EOFException, InputStreamReader}
import java.lang.ProcessBuilder.Redirect
import java.util.Properties

import scala.collection.JavaConversions._
Expand Down Expand Up @@ -58,6 +59,7 @@ case class ScriptTransformation(
child.execute().mapPartitions { iter =>
val cmd = List("/bin/bash", "-c", script)
val builder = new ProcessBuilder(cmd)
builder.redirectError(Redirect.INHERIT)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment explaining why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

builder.redirectError(Redirect.INHERIT) would consuming the error output from buffer and then print it to stderr (inherit the target from the current Scala process).
If without this there would be 2 issues:

  1. The error msg generated by the script process would be hidden.
  2. If the error msg is too big to chock up the buffer, the input logic would be hang (There's are simple steps on jira to reproduce this behavior).

Copy link
Contributor

Choose a reason for hiding this comment

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

Put the comment in the source code.

val proc = builder.start()
val inputStream = proc.getInputStream
val outputStream = proc.getOutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.apache.spark.sql.hive.execution

import org.scalatest.concurrent.Timeouts._
import org.scalatest.time.Span
import org.scalatest.time.Millis

import org.apache.spark.sql.catalyst.DefaultParserDialect
import org.apache.spark.sql.catalyst.analysis.EliminateSubQueries
import org.apache.spark.sql.catalyst.errors.DialectException
Expand Down Expand Up @@ -629,12 +633,24 @@ class SQLQuerySuite extends QueryTest {
.queryExecution.analyzed
}

test("test script transform") {
test("test script transform for stdout") {
val data = (1 to 100000).map { i => (i, i, i) }
data.toDF("d1", "d2", "d3").registerTempTable("script_trans")
assert(100000 ===
sql("SELECT TRANSFORM (d1, d2, d3) USING 'cat' AS (a,b,c) FROM script_trans")
.queryExecution.toRdd.count())
failAfter(Span(20000, Millis)) {
assert(100000 ===
sql("SELECT TRANSFORM (d1, d2, d3) USING 'cat' AS (a,b,c) FROM script_trans")
.queryExecution.toRdd.count())
}
}

test("test script transform for stderr") {
val data = (1 to 100000).map { i => (i, i, i) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This test will flush the stderr while testing, should we generate less data or hide it someway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Filed SPARK-8508 and PR #6925 to shrink unnecessary output.

data.toDF("d1", "d2", "d3").registerTempTable("script_trans")
failAfter(Span(20000, Millis)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

20s is probably long enough that we won't have a problem, but do we really need this? I'm worried if a jenkins machine is overloaded we might have false failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Put it here just to ensure if the deadlock happen again it can be somehow detected. (although in theory it would not be an option any more). Any advice ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I think 20000 ms is reasonable, in most of cases, we will not run the code for such long time, so it's not a problem for Jenkins testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be detected, the build will hang and get aborted. In theory any query could deadlock, so why do we need this extra logic for only this test case?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, without the builder.redirectError(Redirect.INHERIT), it definitely will be blocked here, that's the main purpose of this PR (to fix it). The unit test here to show if the code can not be finised within 20 seconds, then unit test will fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

And what happens if a unit test hangs... the build fails. Any unit test in theory could hang, why is this the only one that we are now making timing dependent?

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't mean we will stop here for 20 seconds. And we don't want to keep the deadlock noticed in 2 hours then jenkins testing timeout, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I got you mean, we thought that would be explicitly to reminder the developer for this specific timeout / failure.
@zhichao-li can you remove this logic?

assert(0 ===
sql("SELECT TRANSFORM (d1, d2, d3) USING 'cat 1>&2' AS (a,b,c) FROM script_trans")
.queryExecution.toRdd.count())
}
}

test("window function: udaf with aggregate expressin") {
Expand Down