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

Supply gcs-connector options from default Configuration #5549

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ lazy val `scio-core` = project
"org.apache.beam" % "beam-runners-google-cloud-dataflow-java" % beamVersion % Provided,
"org.apache.beam" % s"beam-runners-spark-$sparkMajorVersion" % beamVersion % Provided,
"org.apache.beam" % "beam-sdks-java-extensions-google-cloud-platform-core" % beamVersion % Provided,
"org.apache.hadoop" % "hadoop-common" % hadoopVersion % Provided,
"com.google.cloud.bigdataoss" % "gcs-connector" % s"hadoop2-$bigdataossVersion" % Provided,
"com.google.cloud.bigdataoss" % "gcsio" % bigdataossVersion % Provided,
"com.google.cloud.bigdataoss" % "util-hadoop" % s"hadoop2-$bigdataossVersion" % Provided,
// test
"com.lihaoyi" %% "fansi" % fansiVersion % Test,
"com.lihaoyi" %% "pprint" % pprintVersion % Test,
Expand Down
82 changes: 82 additions & 0 deletions scio-core/src/main/scala/com/spotify/scio/ScioContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import scala.collection.mutable.{Buffer => MBuffer}
import scala.concurrent.duration.Duration
import scala.io.Source
import scala.reflect.ClassTag
import scala.util.chaining._
import scala.util.control.NoStackTrace
import scala.util.{Failure, Success, Try}
import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions
Expand Down Expand Up @@ -454,6 +455,87 @@ class ScioContext private[scio] (
o.setScioVersion(BuildInfo.version)
}

{
import org.apache.hadoop.conf.Configuration
import com.google.cloud.hadoop.fs.gcs.{GoogleHadoopFileSystemConfiguration => GfsConfig}
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageReadOptions

try {
// If Hadoop is on the classpath, try to parse default gcs-connector options
val config = new Configuration()
val o = optionsAs[GcsOptions]

o.setGoogleCloudStorageReadOptions(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a method to parse all this for us but it's not public: https://github.com/GoogleCloudDataproc/hadoop-connectors/blob/v3.0.4/gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/GoogleHadoopFileSystemConfiguration.java#L645-L660

I do have a PR up to make it public so hopefully it can be dropped in in a future release.

GoogleCloudStorageReadOptions
.builder()
.pipe(o =>
Option(config.get(GfsConfig.GCS_INPUT_STREAM_FAST_FAIL_ON_NOT_FOUND_ENABLE.getKey))
.map(_.toBoolean)
.fold(o)(o.setFastFailOnNotFound)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_INPUT_STREAM_SUPPORT_GZIP_ENCODING_ENABLE.getKey))
.map(_.toBoolean)
.fold(o)(o.setSupportGzipEncoding)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_INPUT_STREAM_INPLACE_SEEK_LIMIT.getKey))
.map(_.toLong)
.fold(o)(o.setInplaceSeekLimit)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_INPUT_STREAM_FADVISE.getKey))
.map(GoogleCloudStorageReadOptions.Fadvise.valueOf)
.fold(o)(o.setFadvise)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_INPUT_STREAM_MIN_RANGE_REQUEST_SIZE.getKey))
.map(_.toInt)
.fold(o)(o.setMinRangeRequestSize)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_GRPC_CHECKSUMS_ENABLE.getKey))
.map(_.toBoolean)
.fold(o)(o.setGrpcChecksumsEnabled)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_GRPC_READ_TIMEOUT_MS.getKey))
.map(_.toLong)
.fold(o)(o.setGrpcReadTimeoutMillis)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_GRPC_READ_MESSAGE_TIMEOUT_MS.getKey))
.map(_.toLong)
.fold(o)(o.setGrpcReadMessageTimeoutMillis)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_GRPC_READ_METADATA_TIMEOUT_MS.getKey))
.map(_.toLong)
.fold(o)(o.setGrpcReadMetadataTimeoutMillis)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_GRPC_READ_ZEROCOPY_ENABLE.getKey))
.map(_.toBoolean)
.fold(o)(o.setGrpcReadZeroCopyEnabled)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_TRACE_LOG_ENABLE.getKey))
.map(_.toBoolean)
.fold(o)(o.setTraceLogEnabled)
)
.pipe(o =>
Option(config.get(GfsConfig.GCS_TRACE_LOG_TIME_THRESHOLD_MS.getKey))
.map(_.toLong)
.fold(o)(o.setTraceLogTimeThreshold)
)
.build()
)
} catch {
// Hadoop and/or gcs-connector is excluded from classpath, do not try to set options
case _: NoClassDefFoundError | _: NoSuchMethodException =>
}
}

private[scio] def labels: Map[String, String] =
(for {
// Check if class is in classpath
Expand Down
Loading