-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation and warnings related to using different regions for…
… Redshift and S3 Redshift throws extremely confusing errors when the Redshift cluster and S3 bucket are in different AWS regions. This patch expands the documentation to discuss how to fix these errors and adds logic to attempt to automatically detect and warn users when this case occurs. Fixes #87. Author: Josh Rosen <joshrosen@databricks.com> Closes #285 from JoshRosen/cross-region-s3.
- Loading branch information
Showing
7 changed files
with
175 additions
and
0 deletions.
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
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
63 changes: 63 additions & 0 deletions
63
src/it/scala/com/databricks/spark/redshift/CrossRegionIntegrationSuite.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,63 @@ | ||
/* | ||
* Copyright 2016 Databricks | ||
* | ||
* Licensed 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 com.databricks.spark.redshift | ||
|
||
import com.amazonaws.auth.BasicAWSCredentials | ||
import com.amazonaws.services.s3.AmazonS3Client | ||
import org.apache.spark.sql.Row | ||
import org.apache.spark.sql.types.{IntegerType, StructField, StructType} | ||
|
||
/** | ||
* Integration tests where the Redshift cluster and the S3 bucket are in different AWS regions. | ||
*/ | ||
class CrossRegionIntegrationSuite extends IntegrationSuiteBase { | ||
|
||
protected val AWS_S3_CROSS_REGION_SCRATCH_SPACE: String = | ||
loadConfigFromEnv("AWS_S3_CROSS_REGION_SCRATCH_SPACE") | ||
require(AWS_S3_CROSS_REGION_SCRATCH_SPACE.contains("s3n"), "must use s3n:// URL") | ||
|
||
override protected val tempDir: String = AWS_S3_CROSS_REGION_SCRATCH_SPACE + randomSuffix + "/" | ||
|
||
test("write") { | ||
val bucketRegion = Utils.getRegionForS3Bucket( | ||
tempDir, | ||
new AmazonS3Client(new BasicAWSCredentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY))).get | ||
val df = sqlContext.createDataFrame(sc.parallelize(Seq(Row(1)), 1), | ||
StructType(StructField("foo", IntegerType) :: Nil)) | ||
val tableName = s"roundtrip_save_and_load_$randomSuffix" | ||
try { | ||
df.write | ||
.format("com.databricks.spark.redshift") | ||
.option("url", jdbcUrl) | ||
.option("dbtable", tableName) | ||
.option("tempdir", tempDir) | ||
.option("extracopyoptions", s"region '$bucketRegion'") | ||
.save() | ||
// Check that the table exists. It appears that creating a table in one connection then | ||
// immediately querying for existence from another connection may result in spurious "table | ||
// doesn't exist" errors; this caused the "save with all empty partitions" test to become | ||
// flaky (see #146). To work around this, add a small sleep and check again: | ||
if (!DefaultJDBCWrapper.tableExists(conn, tableName)) { | ||
Thread.sleep(1000) | ||
assert(DefaultJDBCWrapper.tableExists(conn, tableName)) | ||
} | ||
} finally { | ||
conn.prepareStatement(s"drop table if exists $tableName").executeUpdate() | ||
conn.commit() | ||
} | ||
} | ||
} |
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
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
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
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