Skip to content

Commit c16bbfd

Browse files
committed
Merge branch 'master' of github.com:apache/spark into hive-distribution
2 parents 32f6826 + f2eb070 commit c16bbfd

143 files changed

Lines changed: 1520 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ unit-tests.log
4949
/lib/
5050
rat-results.txt
5151
scalastyle.txt
52+
53+
# For Hive
54+
metastore_db/
55+
metastore/
56+
warehouse/
57+
TempStatsStore/

bin/compute-classpath.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ CLASSPATH="$SPARK_CLASSPATH:$SPARK_SUBMIT_CLASSPATH:$FWDIR/conf"
3232

3333
ASSEMBLY_DIR="$FWDIR/assembly/target/scala-$SCALA_VERSION"
3434

35+
if [ -n "${JAVA_HOME}" ]; then
36+
JAR_CMD="${JAVA_HOME}/bin/jar"
37+
else
38+
JAR_CMD="jar"
39+
fi
40+
3541
# First check if we have a dependencies jar. If so, include binary classes with the deps jar
3642
if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
3743
CLASSPATH="$CLASSPATH:$FWDIR/core/target/scala-$SCALA_VERSION/classes"
@@ -44,6 +50,7 @@ if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
4450
CLASSPATH="$CLASSPATH:$FWDIR/sql/catalyst/target/scala-$SCALA_VERSION/classes"
4551
CLASSPATH="$CLASSPATH:$FWDIR/sql/core/target/scala-$SCALA_VERSION/classes"
4652
CLASSPATH="$CLASSPATH:$FWDIR/sql/hive/target/scala-$SCALA_VERSION/classes"
53+
CLASSPATH="$CLASSPATH:$FWDIR/yarn/stable/target/scala-$SCALA_VERSION/classes"
4754

4855
DEPS_ASSEMBLY_JAR=$(ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar 2>/dev/null)
4956
CLASSPATH="$CLASSPATH:$DEPS_ASSEMBLY_JAR"
@@ -54,6 +61,14 @@ else
5461
else
5562
ASSEMBLY_JAR=$(ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*.jar 2>/dev/null)
5663
fi
64+
jar_error_check=$($JAR_CMD -tf $ASSEMBLY_JAR org/apache/spark/SparkContext 2>&1)
65+
if [[ "$jar_error_check" =~ "invalid CEN header" ]]; then
66+
echo "Loading Spark jar with '$JAR_CMD' failed. "
67+
echo "This is likely because Spark was compiled with Java 7 and run "
68+
echo "with Java 6. (see SPARK-1703). Please use Java 7 to run Spark "
69+
echo "or build Spark with Java 6."
70+
exit 1
71+
fi
5772
CLASSPATH="$CLASSPATH:$ASSEMBLY_JAR"
5873
fi
5974

bin/spark-class

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ if [ -e "$TOOLS_DIR"/target/spark-tools*[0-9Tg].jar ]; then
138138
fi
139139

140140
# Compute classpath using external script
141-
CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
141+
classpath_output=$($FWDIR/bin/compute-classpath.sh)
142+
if [[ "$?" != "0" ]]; then
143+
echo "$classpath_output"
144+
exit 1
145+
else
146+
CLASSPATH=$classpath_output
147+
fi
148+
142149
if [[ "$1" =~ org.apache.spark.tools.* ]]; then
143150
CLASSPATH="$CLASSPATH:$SPARK_TOOLS_JAR"
144151
fi

bin/spark-submit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
export SPARK_HOME="$(cd `dirname $0`/..; pwd)"
21-
ORIG_ARGS=$@
21+
ORIG_ARGS=("$@")
2222

2323
while (($#)); do
2424
if [ "$1" = "--deploy-mode" ]; then
@@ -39,5 +39,5 @@ if [ ! -z $DRIVER_MEMORY ] && [ ! -z $DEPLOY_MODE ] && [ $DEPLOY_MODE = "client"
3939
export SPARK_MEM=$DRIVER_MEMORY
4040
fi
4141

42-
$SPARK_HOME/bin/spark-class org.apache.spark.deploy.SparkSubmit $ORIG_ARGS
42+
$SPARK_HOME/bin/spark-class org.apache.spark.deploy.SparkSubmit "${ORIG_ARGS[@]}"
4343

core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
<groupId>com.google.guava</groupId>
7070
<artifactId>guava</artifactId>
7171
</dependency>
72+
<dependency>
73+
<groupId>org.apache.commons</groupId>
74+
<artifactId>commons-lang3</artifactId>
75+
</dependency>
7276
<dependency>
7377
<groupId>com.google.code.findbugs</groupId>
7478
<artifactId>jsr305</artifactId>

core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ private[spark] class PythonRDD[T: ClassTag](
5454
override def compute(split: Partition, context: TaskContext): Iterator[Array[Byte]] = {
5555
val startTime = System.currentTimeMillis
5656
val env = SparkEnv.get
57-
val worker = env.createPythonWorker(pythonExec, envVars.toMap)
57+
val worker: Socket = env.createPythonWorker(pythonExec, envVars.toMap)
58+
59+
// Ensure worker socket is closed on task completion. Closing sockets is idempotent.
60+
context.addOnCompleteCallback(() =>
61+
try {
62+
worker.close()
63+
} catch {
64+
case e: Exception => logWarning("Failed to close worker socket", e)
65+
}
66+
)
5867

5968
@volatile var readerException: Exception = null
6069

core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,36 @@ import org.apache.hadoop.mapred.JobConf
2424
import org.apache.hadoop.security.Credentials
2525
import org.apache.hadoop.security.UserGroupInformation
2626

27-
import org.apache.spark.{SparkContext, SparkException}
27+
import org.apache.spark.{Logging, SparkContext, SparkException}
2828

2929
import scala.collection.JavaConversions._
3030

3131
/**
3232
* Contains util methods to interact with Hadoop from Spark.
3333
*/
34-
class SparkHadoopUtil {
34+
class SparkHadoopUtil extends Logging {
3535
val conf: Configuration = newConfiguration()
3636
UserGroupInformation.setConfiguration(conf)
3737

38-
def runAsUser(user: String)(func: () => Unit) {
38+
/**
39+
* Runs the given function with a Hadoop UserGroupInformation as a thread local variable
40+
* (distributed to child threads), used for authenticating HDFS and YARN calls.
41+
*
42+
* IMPORTANT NOTE: If this function is going to be called repeated in the same process
43+
* you need to look https://issues.apache.org/jira/browse/HDFS-3545 and possibly
44+
* do a FileSystem.closeAllForUGI in order to avoid leaking Filesystems
45+
*/
46+
def runAsSparkUser(func: () => Unit) {
47+
val user = Option(System.getenv("SPARK_USER")).getOrElse(SparkContext.SPARK_UNKNOWN_USER)
3948
if (user != SparkContext.SPARK_UNKNOWN_USER) {
49+
logDebug("running as user: " + user)
4050
val ugi = UserGroupInformation.createRemoteUser(user)
4151
transferCredentials(UserGroupInformation.getCurrentUser(), ugi)
4252
ugi.doAs(new PrivilegedExceptionAction[Unit] {
4353
def run: Unit = func()
4454
})
4555
} else {
56+
logDebug("running as SPARK_UNKNOWN_USER")
4657
func()
4758
}
4859
}

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.spark.deploy
1919

2020
import java.io.{File, PrintStream}
21+
import java.lang.reflect.InvocationTargetException
2122
import java.net.{URI, URL}
2223

2324
import scala.collection.mutable.{ArrayBuffer, HashMap, Map}
@@ -137,7 +138,7 @@ object SparkSubmit {
137138
throw new Exception(msg)
138139
}
139140
}
140-
141+
141142
// Special flag to avoid deprecation warnings at the client
142143
sysProps("SPARK_SUBMIT") = "true"
143144

@@ -253,7 +254,14 @@ object SparkSubmit {
253254

254255
val mainClass = Class.forName(childMainClass, true, loader)
255256
val mainMethod = mainClass.getMethod("main", new Array[String](0).getClass)
256-
mainMethod.invoke(null, childArgs.toArray)
257+
try {
258+
mainMethod.invoke(null, childArgs.toArray)
259+
} catch {
260+
case e: InvocationTargetException => e.getCause match {
261+
case cause: Throwable => throw cause
262+
case null => throw e
263+
}
264+
}
257265
}
258266

259267
private def addJarToClasspath(localJar: String, loader: ExecutorURLClassLoader) {

core/src/main/scala/org/apache/spark/deploy/SparkSubmitArguments.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) {
284284
| --master MASTER_URL spark://host:port, mesos://host:port, yarn, or local.
285285
| --deploy-mode DEPLOY_MODE Mode to deploy the app in, either 'client' or 'cluster'.
286286
| --class CLASS_NAME Name of your app's main class (required for Java apps).
287-
| --arg ARG Argument to be passed to your application's main class. This
288-
| option can be specified multiple times for multiple args.
289287
| --name NAME The name of your application (Default: 'Spark').
290288
| --jars JARS A comma-separated list of local jars to include on the
291289
| driver classpath and that SparkContext.addJar will work

core/src/main/scala/org/apache/spark/deploy/client/AppClient.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ private[spark] class AppClient(
9292
if (registered) {
9393
retryTimer.cancel()
9494
} else if (retries >= REGISTRATION_RETRIES) {
95-
logError("All masters are unresponsive! Giving up.")
96-
markDead()
95+
markDead("All masters are unresponsive! Giving up.")
9796
} else {
9897
tryRegisterAllMasters()
9998
}
@@ -126,8 +125,7 @@ private[spark] class AppClient(
126125
listener.connected(appId)
127126

128127
case ApplicationRemoved(message) =>
129-
logError("Master removed our application: %s; stopping client".format(message))
130-
markDisconnected()
128+
markDead("Master removed our application: %s".format(message))
131129
context.stop(self)
132130

133131
case ExecutorAdded(id: Int, workerId: String, hostPort: String, cores: Int, memory: Int) =>
@@ -158,7 +156,7 @@ private[spark] class AppClient(
158156
logWarning(s"Could not connect to $address: $cause")
159157

160158
case StopAppClient =>
161-
markDead()
159+
markDead("Application has been stopped.")
162160
sender ! true
163161
context.stop(self)
164162
}
@@ -173,9 +171,9 @@ private[spark] class AppClient(
173171
}
174172
}
175173

176-
def markDead() {
174+
def markDead(reason: String) {
177175
if (!alreadyDead) {
178-
listener.dead()
176+
listener.dead(reason)
179177
alreadyDead = true
180178
}
181179
}

0 commit comments

Comments
 (0)