-
Notifications
You must be signed in to change notification settings - Fork 1
timeout handling for get instances SA-25112 #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,13 @@ import org.apache.zookeeper.CreateMode | |
|
|
||
| import scala.concurrent.Future | ||
| import ZookeeperInstanceStorage._ | ||
| import akka.actor.ActorSystem | ||
| import akkeeper.api.InstanceId | ||
|
|
||
| private[akkeeper] class ZookeeperInstanceStorage(config: ZookeeperClientConfig) | ||
| import scala.concurrent.duration.{DurationInt, FiniteDuration} | ||
| import scala.util.Try | ||
|
|
||
| private[akkeeper] class ZookeeperInstanceStorage(config: ZookeeperClientConfig)(implicit system: ActorSystem) | ||
| extends BaseZookeeperStorage with InstanceStorage { | ||
|
|
||
| protected override val zookeeperClient = | ||
|
|
@@ -50,23 +54,40 @@ private[akkeeper] class ZookeeperInstanceStorage(config: ZookeeperClientConfig) | |
| .map(fromBytes[InstanceInfo]) | ||
| } | ||
|
|
||
| //akka-http default timeout is 20 seconds, so ensure that the call does not exceed it | ||
| //timeout outer future in 19 seconds | ||
| override def getInstances: Future[Seq[InstanceId]] = { | ||
| val instancesFuture = for { | ||
| val t0 = System.nanoTime() | ||
| val instancesFuture: Future[Seq[Future[Seq[String]]]] = for { | ||
| //timeout | ||
| containers <- zookeeperClient.children("") | ||
| } yield for { | ||
| container <- containers | ||
| } yield zookeeperClient.children(container) | ||
| instancesFuture | ||
| val expectedExecution = instancesFuture | ||
| .flatMap(f => Future.sequence(f).map(_.flatten)) | ||
| .map(_.map(pathToInstanceId)) | ||
| .recover(notFoundToEmptySeq[InstanceId]) | ||
| expectedExecution.onComplete { result:Try[Seq[InstanceId]] => | ||
|
Collaborator
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. Is this future going to be completed on akka-http timeout?
Author
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. Yes - it is independent. Akka-http waits for completion of http request for |
||
| val t1 = System.nanoTime() | ||
| val nanoDelta = t1 - t0 | ||
| val secondsDelta = nanoDelta.toDouble / 1000000000L | ||
| val statusMsg = if(result.isSuccess) {"succeeded"} else {s"failed with ${result.failed.get}"} | ||
| if(secondsDelta >= 20.0) { | ||
| system.log.warning(s"getInstances TIMEOUTED, took ${secondsDelta} seconds and ${statusMsg}") | ||
| } else { | ||
| system.log.info(s"getInstances took ${secondsDelta} seconds and ${statusMsg}") | ||
| } | ||
| }(system.dispatcher) | ||
| expectedExecution | ||
| } | ||
|
|
||
| override def getInstancesByContainer(containerName: String): Future[Seq[InstanceId]] = { | ||
| zookeeperClient.children(containerName) | ||
| .map(_.map(pathToInstanceId)) | ||
| .recover(notFoundToEmptySeq[InstanceId]) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private[akkeeper] object ZookeeperInstanceStorage { | ||
|
|
||
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.
Why did you change it?
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.
in
ZookeeperClientwe have.retryPolicy(new ExponentialBackoffRetry(config.connectionIntervalMs, config.maxRetries))- so we start from 3000ms and then exponentially backoff up tomax-retries. 3000 ms * (2 ^ 8) is already around 12 minutes - way over our timeout. 500ms brings that time to around 2 minutes max