Skip to content

Retry "file status" request with exponential backoff if it failed #121

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

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ object SparkDruidIndexer {
s => {
val p = new Path(s)
val fs = p.getFileSystem(sc.hadoopConfiguration)
fs.getFileStatus(p).getLen
// You can send 3,500 PUT/COPY/POST/DELETE or 5,500 GET/HEAD requests per second per prefix in an S3 bucket
// This block catches "503 Slow Down" error, retries a request and sleeps for up to 6 (=2+4) seconds in total
retryWithExponentialBackoff(3) {

Choose a reason for hiding this comment

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

that's cool.
I wonder if you have any idea how to retry SparkContext.textFile the same way?

Copy link
Author

Choose a reason for hiding this comment

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

let's try these props, not sure if they are supported

spark.hadoop.fs.s3.maxRetries=3
spark.hadoop.fs.s3.consistent.retryPolicyType=exponential

Choose a reason for hiding this comment

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

For example, we could still be hit during write operations:

2021-04-06T13:23:04,926 WARN [task-result-getter-0] org.apache.spark.scheduler.TaskSetManager - Lost task 210.1 in stage 3.0 (TID 12452, 172.19.15.254, executor 122): java.lang.RuntimeException: org.apache.hadoop.fs.s3.S3Exception: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 503, ResponseStatus: Slow Down, XML Error Message: SlowDownPlease reduce your request rate.5HRTEN7YXGVNM9EF+LUSwUnkV+XIW3aJPuhz24RwuwZlhCD/8oYfHMoWq0i2qnnTyugAHr7bGb46ahZazUi0E/6z2BY= at com.metamx.starfire.batch.shaded.com.google.common.base.Throwables.propagate(Throwables.java:240) at com.metamx.hadoop.Utils.retry(Utils.java:30) at com.metamx.hadoop.MultipleOutputFormat.getBaseRecordWriter(MultipleOutputFormat.java:103) at com.metamx.hadoop.MultipleOutputFormat$2.getStore(MultipleOutputFormat.java:239) at com.metamx.hadoop.MultipleOutputFormat$2.write(MultipleOutputFormat.java:205) at com.metamx.hadoop.PipesOutputFormat$2.write(PipesOutputFormat.java:192) at com.metamx.hadoop.PipesOutputFormat$2.write(PipesOutputFormat.java:185) at com.metamx.starfire.spark.sink.MMXDeprecatedOutputFormatWrapper$RecordWriterWrapper.write(MMXDeprecatedOutputFormatWrapper.java:108) at org.apache.spark.SparkHadoopWriter.write(SparkHadoopWriter.scala:95) at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$7.apply$mcV$sp(PairRDDFunctions.scala:1212) at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$7.apply(PairRDDFunctions.scala:1210) at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$7.apply(PairRDDFunctions.scala:1210) at org.apache.spark.util.Utils$.tryWithSafeFinallyAndFailureCallbacks(Utils.scala:1341) at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13.apply(PairRDDFunctions.scala:1218) at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13.apply(PairRDDFunctions.scala:1197) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87) at org.apache.spark.scheduler.Task.run(Task.scala:99) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.hadoop.fs.s3.S3Exception: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 503, ResponseStatus: Slow Down, XML Error Message: SlowDownPlease reduce your request rate.5HRTEN7YXGVNM9EF+LUSwUnkV+XIW3aJPuhz24RwuwZlhCD/8oYfHMoWq0i2qnnTyugAHr7bGb46ahZazUi0E/6z2BY= at org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.propagateRootCause(Jets3tNativeFileSystemStore.java:386) at org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.storeEmptyFile(Jets3tNativeFileSystemStore.java:160) at sun.reflect.GeneratedMethodAccessor268.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:190) at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:103) at org.apache.hadoop.fs.s3native.$Proxy7.storeEmptyFile(Unknown Source) at org.apache.hadoop.fs.s3native.NativeS3FileSystem.createParent(NativeS3FileSystem.java:575) at org.apache.hadoop.fs.s3native.NativeS3FileSystem.delete(NativeS3FileSystem.java:396) at com.metamx.hadoop.MultipleOutputFormat.deleteExistingFiles(MultipleOutputFormat.java:178) at com.metamx.hadoop.MultipleOutputFormat.access$000(MultipleOutputFormat.java:30) at com.metamx.hadoop.MultipleOutputFormat$1.call(MultipleOutputFormat.java:109) at com.metamx.hadoop.Utils.retry(Utils.java:24) ... 19 more Caused by: org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 503, ResponseStatus: Slow Down, XML Error Message: SlowDownPlease reduce your request rate.5HRTEN7YXGVNM9EF+LUSwUnkV+XIW3aJPuhz24RwuwZlhCD/8oYfHMoWq0i2qnnTyugAHr7bGb46ahZazUi0E/6z2BY= at org.jets3t.service.S3Service.putObject(S3Service.java:2358) at org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.storeEmptyFile(Jets3tNativeFileSystemStore.java:158) ... 31 more-

Copy link
Author

Choose a reason for hiding this comment

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

don't know where it goes from but seems like this stack trace also has RetryInvocationHandler.java so the properties I shared might help if they are supported

fs.getFileStatus(p).getLen
}
}
).sum
val startingPartitions = (totalGZSize / (100L << 20)).toInt + 1
Expand Down
24 changes: 24 additions & 0 deletions src/main/scala/io/druid/indexer/spark/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.druid.indexer

import scala.util.Failure
import scala.util.Random
import scala.util.Success
import scala.util.Try

package object spark {
@annotation.tailrec
def retryWithExponentialBackoff[T](n: Int, sleepMillis: Long)(fn: => T): T = {
Try { fn } match {
case Success(x) => x
case _ if n > 1 => Thread.sleep(sleepMillis); retryWithExponentialBackoff(n - 1, 2 * sleepMillis)(fn)
case Failure(e) => throw e
}
}

/**
* Retry on any non-fatal exception with exponential backoff starting from 1000-2000 millis of sleep
*/
def retryWithExponentialBackoff[T](n: Int)(fn: => T): T = {
retryWithExponentialBackoff(n, ((1 + Random.nextDouble()) * 1000).toLong)(fn)
}
}