From f74064df7c00af07ab2cc63d8bb035dea45a0368 Mon Sep 17 00:00:00 2001 From: Harsh Gupta Date: Thu, 21 May 2015 23:36:02 +0530 Subject: [PATCH 1/3] Retrieving properties from property list using iterator and while loop instead of chained functions --- .../src/main/scala/org/apache/spark/rpc/RpcEnv.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala index 71924475826d9..c8aab1e1ab405 100644 --- a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala +++ b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala @@ -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){ + val propKey = itr.next() + conf.getOption(propKey) match { + case Some(prop) => foundProp = (propKey,prop) + case None => + } + } val timeout = { Utils.timeStringAsSeconds(foundProp._2) seconds } new RpcTimeout(timeout, messagePrefix + foundProp._1) } From 0ee56423662cf1a4a993edf940b53ca97898ddfb Mon Sep 17 00:00:00 2001 From: Harsh Gupta Date: Fri, 22 May 2015 01:52:42 +0530 Subject: [PATCH 2/3] Changing the loop condition to halt at the first match in the property list for RpcEnv exception catch --- core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala index c8aab1e1ab405..f2d849786fdbf 100644 --- a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala +++ b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala @@ -266,7 +266,7 @@ object RpcTimeout { // Find the first set property or use the default value with the first property val itr = timeoutPropList.iterator var foundProp = (timeoutPropList.head,defaultValue) - while (itr.hasNext){ + while (itr.hasNext && (foundProp == (timeoutPropList.head,defaultValue))){ val propKey = itr.next() conf.getOption(propKey) match { case Some(prop) => foundProp = (propKey,prop) From 4be3a8d70fb8dd1b4aa864cd0d9a38bb8dbee5ce Mon Sep 17 00:00:00 2001 From: Harsh Gupta Date: Sun, 24 May 2015 12:25:32 +0530 Subject: [PATCH 3/3] Modifying loop condition to find property match --- core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala index f2d849786fdbf..48e315249ffa6 100644 --- a/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala +++ b/core/src/main/scala/org/apache/spark/rpc/RpcEnv.scala @@ -265,15 +265,16 @@ object RpcTimeout { // Find the first set property or use the default value with the first property val itr = timeoutPropList.iterator - var foundProp = (timeoutPropList.head,defaultValue) - while (itr.hasNext && (foundProp == (timeoutPropList.head,defaultValue))){ + var foundProp = None: Option[(String, String)] + while (itr.hasNext && foundProp.isEmpty){ val propKey = itr.next() conf.getOption(propKey) match { - case Some(prop) => foundProp = (propKey,prop) + case Some(prop) => foundProp = Some(propKey,prop) case None => } } - val timeout = { Utils.timeStringAsSeconds(foundProp._2) seconds } - new RpcTimeout(timeout, messagePrefix + foundProp._1) + val finalProp = foundProp.getOrElse(timeoutPropList.head, defaultValue) + val timeout = { Utils.timeStringAsSeconds(finalProp._2) seconds } + new RpcTimeout(timeout, messagePrefix + finalProp._1) } }