-
Notifications
You must be signed in to change notification settings - Fork 28k
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-35878][CORE] Add fs.s3a.endpoint if unset and fs.s3a.endpoint.region is null. #33064
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,6 +421,9 @@ private[spark] object SparkHadoopUtil extends Logging { | |
* Returns a Configuration object with Spark configuration applied on top. Unlike | ||
* the instance method, this will always return a Configuration instance, and not a | ||
* cluster manager-specific type. | ||
* The configuration will load all default values set in core-default.xml, | ||
* and if found on the classpath, those of core-site.xml. | ||
* This is done before the spark overrides are applied. | ||
*/ | ||
private[spark] def newConfiguration(conf: SparkConf): Configuration = { | ||
val hadoopConf = new Configuration() | ||
|
@@ -487,6 +490,18 @@ private[spark] object SparkHadoopUtil extends Logging { | |
if (conf.getOption("spark.hadoop.fs.s3a.downgrade.syncable.exceptions").isEmpty) { | ||
hadoopConf.set("fs.s3a.downgrade.syncable.exceptions", "true") | ||
} | ||
// In Hadoop 3.3.1, AWS region handling with the default "" endpoint only works | ||
// in EC2 deployments or when the AWS CLI is installed. | ||
// The workaround is to set the name of the S3 endpoint explicitly, | ||
// if not already set. See HADOOP-17771. | ||
// This change is harmless on older versions and compatible with | ||
// later Hadoop releases | ||
if (hadoopConf.get("fs.s3a.endpoint", "").isEmpty && | ||
hadoopConf.get("fs.s3a.endpoint.region") == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two more spaces. |
||
// set to US central endpoint which can also connect to buckets | ||
// in other regions at the expense of a HEAD request during fs creation | ||
hadoopConf.set("fs.s3a.endpoint", "s3.amazonaws.com") | ||
} | ||
} | ||
|
||
private def appendSparkHiveConfigs(conf: SparkConf, hadoopConf: Configuration): Unit = { | ||
|
96 changes: 96 additions & 0 deletions
96
core/src/test/scala/org/apache/spark/deploy/SparkHadoopUtilSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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.deploy | ||
|
||
import org.apache.hadoop.conf.Configuration | ||
|
||
import org.apache.spark.{SparkConf, SparkFunSuite} | ||
|
||
class SparkHadoopUtilSuite extends SparkFunSuite { | ||
|
||
/** | ||
* Verify that spark.hadoop options are propagated, and that | ||
* the default s3a options are set as expected. | ||
*/ | ||
test("appendSparkHadoopConfigs with propagation and defaults") { | ||
val sc = new SparkConf() | ||
val hadoopConf = new Configuration(false) | ||
sc.set("spark.hadoop.orc.filterPushdown", "true") | ||
new SparkHadoopUtil().appendSparkHadoopConfigs(sc, hadoopConf) | ||
assertConfigValue(hadoopConf, "orc.filterPushdown", "true" ) | ||
assertConfigValue(hadoopConf, "fs.s3a.downgrade.syncable.exceptions", "true") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding this. |
||
assertConfigValue(hadoopConf, "fs.s3a.endpoint", "s3.amazonaws.com") | ||
} | ||
|
||
/** | ||
* An empty S3A endpoint will be overridden just as a null value | ||
* would. | ||
*/ | ||
test("appendSparkHadoopConfigs with S3A endpoint set to empty string") { | ||
val sc = new SparkConf() | ||
val hadoopConf = new Configuration(false) | ||
sc.set("spark.hadoop.fs.s3a.endpoint", "") | ||
new SparkHadoopUtil().appendSparkHadoopConfigs(sc, hadoopConf) | ||
assertConfigValue(hadoopConf, "fs.s3a.endpoint", "s3.amazonaws.com") | ||
} | ||
|
||
/** | ||
* Explicitly set the patched s3a options and verify that they are not overridden. | ||
*/ | ||
test("appendSparkHadoopConfigs with S3A options explicitly set") { | ||
val sc = new SparkConf() | ||
val hadoopConf = new Configuration(false) | ||
sc.set("spark.hadoop.fs.s3a.downgrade.syncable.exceptions", "false") | ||
sc.set("spark.hadoop.fs.s3a.endpoint", "s3-eu-west-1.amazonaws.com") | ||
new SparkHadoopUtil().appendSparkHadoopConfigs(sc, hadoopConf) | ||
assertConfigValue(hadoopConf, "fs.s3a.downgrade.syncable.exceptions", "false") | ||
assertConfigValue(hadoopConf, "fs.s3a.endpoint", | ||
"s3-eu-west-1.amazonaws.com") | ||
} | ||
|
||
/** | ||
* If the endpoint region is set (even to a blank string) in | ||
* "spark.hadoop.fs.s3a.endpoint.region" then the endpoint is not set, | ||
* even when the s3a endpoint is "". | ||
* This supports a feature in later hadoop versions where this configuration | ||
* pair triggers a revert to the "SDK to work out the region" algorithm, | ||
* which works on EC2 deployments. | ||
*/ | ||
test("appendSparkHadoopConfigs with S3A endpoint region set to an empty string") { | ||
val sc = new SparkConf() | ||
val hadoopConf = new Configuration(false) | ||
sc.set("spark.hadoop.fs.s3a.endpoint.region", "") | ||
new SparkHadoopUtil().appendSparkHadoopConfigs(sc, hadoopConf) | ||
// the endpoint value will not have been set | ||
assertConfigValue(hadoopConf, "fs.s3a.endpoint", null) | ||
} | ||
|
||
/** | ||
* Assert that a hadoop configuration option has the expected value. | ||
* @param hadoopConf configuration to query | ||
* @param key key to look up | ||
* @param expected expected value. | ||
*/ | ||
private def assertConfigValue( | ||
hadoopConf: Configuration, | ||
key: String, | ||
expected: String): Unit = { | ||
assert(hadoopConf.get(key) === expected, | ||
s"Mismatch in expected value of $key") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
AWS_REGION
as a workaround, too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's automatically picked up in the default chain, but since you have to set it everywhere it's not something you can rely on.