Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3397,7 +3397,9 @@ object SparkContext extends Logging {
.getAllWithPrefix("spark.hadoop.fs.s3a.bucket.")
.filter(_._1.endsWith(".committer.magic.enabled"))
.filter(_._2.equalsIgnoreCase("true"))
if (magicCommitterConfs.nonEmpty) {
if (magicCommitterConfs.nonEmpty &&
Utils.classIsLoadable("org.apache.spark.internal.io.cloud.BindingParquetOutputCommitter") &&
Utils.classIsLoadable("org.apache.spark.internal.io.cloud.PathOutputCommitProtocol")) {
// Try to enable S3 magic committer if missing
conf.setIfMissing("spark.hadoop.fs.s3a.committer.magic.enabled", "true")
if (conf.get("spark.hadoop.fs.s3a.committer.magic.enabled").equals("true")) {
Expand Down
20 changes: 8 additions & 12 deletions core/src/test/scala/org/apache/spark/SparkContextSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,13 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext with Eventu
}

test("SPARK-35383: Fill missing S3A magic committer configs if needed") {
Seq(
"org.apache.spark.internal.io.cloud.BindingParquetOutputCommitter",
"org.apache.spark.internal.io.cloud.PathOutputCommitProtocol"
).foreach { className =>
assert(!Utils.classIsLoadable(className))
}

val c1 = new SparkConf().setAppName("s3a-test").setMaster("local")
sc = new SparkContext(c1)
assert(!sc.getConf.contains("spark.hadoop.fs.s3a.committer.name"))
Expand All @@ -1287,18 +1294,7 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext with Eventu
resetSparkContext()
val c3 = c1.clone.set("spark.hadoop.fs.s3a.bucket.mybucket.committer.magic.enabled", "true")
sc = new SparkContext(c3)
Seq(
"spark.hadoop.fs.s3a.committer.magic.enabled" -> "true",
"spark.hadoop.fs.s3a.committer.name" -> "magic",
"spark.hadoop.mapreduce.outputcommitter.factory.scheme.s3a" ->
"org.apache.hadoop.fs.s3a.commit.S3ACommitterFactory",
"spark.sql.parquet.output.committer.class" ->
"org.apache.spark.internal.io.cloud.BindingParquetOutputCommitter",
"spark.sql.sources.commitProtocolClass" ->
"org.apache.spark.internal.io.cloud.PathOutputCommitProtocol"
).foreach { case (k, v) =>
assert(v == sc.getConf.get(k))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the classes are not available in core module, the existing test case is moved to hadoop-cloud.

assert(!sc.getConf.contains("spark.hadoop.fs.s3a.committer.name"))

// Respect a user configuration
resetSparkContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark

import org.scalatest.BeforeAndAfterEach

import org.apache.spark.util.Utils

class SparkContextSuite extends SparkFunSuite with BeforeAndAfterEach {
@transient var sc: SparkContext = _

override def afterEach(): Unit = {
try {
if (sc != null) {
sc.stop()
}
} finally {
super.afterEach()
}
}

test("SPARK-35383: Fill missing S3A magic committer configs if needed") {
Seq(
"org.apache.spark.internal.io.cloud.BindingParquetOutputCommitter",
"org.apache.spark.internal.io.cloud.PathOutputCommitProtocol"
).foreach { className =>
assert(Utils.classIsLoadable(className))
}

val c1 = new SparkConf().setAppName("s3a-test").setMaster("local")
sc = new SparkContext(c1)
assert(!sc.getConf.contains("spark.hadoop.fs.s3a.committer.name"))
sc.stop()

val c2 = c1.clone.set("spark.hadoop.fs.s3a.bucket.mybucket.committer.magic.enabled", "false")
sc = new SparkContext(c2)
assert(!sc.getConf.contains("spark.hadoop.fs.s3a.committer.name"))
sc.stop()

val c3 = c1.clone.set("spark.hadoop.fs.s3a.bucket.mybucket.committer.magic.enabled", "true")
sc = new SparkContext(c3)
Seq(
"spark.hadoop.fs.s3a.committer.magic.enabled" -> "true",
"spark.hadoop.fs.s3a.committer.name" -> "magic",
"spark.hadoop.mapreduce.outputcommitter.factory.scheme.s3a" ->
"org.apache.hadoop.fs.s3a.commit.S3ACommitterFactory",
"spark.sql.parquet.output.committer.class" ->
"org.apache.spark.internal.io.cloud.BindingParquetOutputCommitter",
"spark.sql.sources.commitProtocolClass" ->
"org.apache.spark.internal.io.cloud.PathOutputCommitProtocol"
).foreach { case (k, v) =>
assert(v == sc.getConf.get(k))
}
sc.stop()

// Respect a user configuration
val c4 = c1.clone
.set("spark.hadoop.fs.s3a.committer.magic.enabled", "false")
.set("spark.hadoop.fs.s3a.bucket.mybucket.committer.magic.enabled", "true")
sc = new SparkContext(c4)
Seq(
"spark.hadoop.fs.s3a.committer.magic.enabled" -> "false",
"spark.hadoop.fs.s3a.committer.name" -> null,
"spark.hadoop.mapreduce.outputcommitter.factory.scheme.s3a" -> null,
"spark.sql.parquet.output.committer.class" -> null,
"spark.sql.sources.commitProtocolClass" -> null
).foreach { case (k, v) =>
if (v == null) {
assert(!sc.getConf.contains(k))
} else {
assert(v == sc.getConf.get(k))
}
}
sc.stop()
}
}