Skip to content
Merged
Changes from 2 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
12 changes: 9 additions & 3 deletions core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,15 @@ object RpcTimeout {
require(timeoutPropList.nonEmpty)

// Find the first set property or use the default value with the first property
val foundProp = timeoutPropList.view.map(x => (x, conf.getOption(x))).filter(_._2.isDefined).
map(y => (y._1, y._2.get)).headOption.getOrElse(timeoutPropList.head, defaultValue)

val itr = timeoutPropList.iterator
var foundProp = (timeoutPropList.head,defaultValue)
while (itr.hasNext && (foundProp == (timeoutPropList.head,defaultValue))){
Copy link
Owner

Choose a reason for hiding this comment

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

@hardmettle not to nitpick, this should work fine, but comparing tuples of strings to check if it's found yet seems a little unnecessary. What do you think about just defining a Boolean and mark it as true once the property is found, then stop the loop?

Copy link
Author

Choose a reason for hiding this comment

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

I have got no issues with that. I was anyways not convinced with the idea of using a "var" and an idiomatic way to loop . I thought of keeping it as little messy as I could by avoiding another boolean variable.What do you think @BryanCutler & @squito ?

Copy link
Owner

Choose a reason for hiding this comment

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

It's up to you. For me, I think the loop might be a little cleaner by using an Option like this:

 var foundProp =  None: Option[(String, String)]
 while (itr.hasNext && foundProp.isEmpty){
   ...

Then get the final result with foundProp.getOrElse(timeoutPropList.head, defaultValue). It's probably not a big deal so if you prefer the way it is now, I can merge that.

Copy link
Author

Choose a reason for hiding this comment

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

@BryanCutler Thank you for the suggestion , made the changes the way you described.

val propKey = itr.next()
conf.getOption(propKey) match {
case Some(prop) => foundProp = (propKey,prop)
Copy link

Choose a reason for hiding this comment

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

this logic is a little different than the original -- it'll take the last set property, rather than the first.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for noticing @squito . Made the changes accordingly. :)

case None =>
}
}
val timeout = { Utils.timeStringAsSeconds(foundProp._2) seconds }
new RpcTimeout(timeout, messagePrefix + foundProp._1)
}
Expand Down