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

[SPARK-1779] Throw an exception if memory fractions are not between 0 and 1 #714

Closed
wants to merge 13 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ private[spark] object BlockManager extends Logging {

def getMaxMemory(conf: SparkConf): Long = {
val memoryFraction = conf.getDouble("spark.storage.memoryFraction", 0.6)
if (memoryFraction > 1 && memoryFraction < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should throw an IllegalArgumentException.

Preconditions.checkArgument(0 < memoryFraction && 1 > memoryFraction, 
  "spark.storage.memoryFraction should be between 0 and 1.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for that

throw new Exception("spark.storage.memoryFraction should be between 0 and 1.")
}
(Runtime.getRuntime.maxMemory * memoryFraction).toLong
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class ExternalAppendOnlyMap[K, V, C](
private val maxMemoryThreshold = {
val memoryFraction = sparkConf.getDouble("spark.shuffle.memoryFraction", 0.3)
val safetyFraction = sparkConf.getDouble("spark.shuffle.safetyFraction", 0.8)
if (memoryFraction > 1 && memoryFraction < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should or(||) instead of and(&&).
[memoryFraction > 1 && memoryFraction < 0] => [memoryFraction > 1 || memoryFraction < 0]
The same to safetyFraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i made a mistake

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, good call

throw new Exception("spark.shuffle.memoryFraction should be between 0 and 1.")
}
if (safetyFraction > 1 && safetyFraction < 0) {
throw new Exception("spark.shuffle.safetyFraction should be between 0 and 1.")
}
(Runtime.getRuntime.maxMemory * memoryFraction * safetyFraction).toLong
}

Expand Down