-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-5932][CORE] Use consistent naming for size properties #5574
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
Changes from 1 commit
d7a06b8
a99032f
e92caf7
8be2f83
733ec9f
dfec4da
0e1567c
15e8dea
270cfe3
cb0c6b7
8c884fa
1dc0444
db9a963
5390fd9
09ea450
747393a
a9f4fcf
851d691
475370a
0cdff35
b809a78
eba4de6
1fbd435
2d15681
ae7e9f6
afc9a38
7a6c847
5d29f90
928469e
35a7fa7
0f4443e
f15f209
f32bc01
69e2f20
54b78b4
c7803cd
fe286b4
d3d09b6
84a2581
8b43748
e428049
3dfae96
22413b1
9ee779c
852a407
fc85733
2ab886b
49a8720
11f6999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…erializer.mb to new values.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1082,7 +1082,7 @@ private[spark] object Utils extends Logging { | |
| def memoryStringToMb(str: String): Int = { | ||
| // Convert to bytes, rather than directly to MB, because when no units are specified the unit | ||
| // is assumed to be bytes | ||
| (JavaUtils.byteStringAsBytes(str) / 1024.0d / 1024.0d).toInt | ||
| (JavaUtils.byteStringAsBytes(str) / 1024 / 1024).toInt | ||
|
Contributor
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. super nit: you could drop the |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,11 @@ | |
|
|
||
| public enum ByteUnit { | ||
| BYTE (1), | ||
| KiB (1024l), | ||
| MiB ((long) Math.pow(1024l, 2l)), | ||
| GiB ((long) Math.pow(1024l, 3l)), | ||
| TiB ((long) Math.pow(1024l, 4l)), | ||
| PiB ((long) Math.pow(1024l, 5l)); | ||
| KiB (1024L), | ||
| MiB ((long) Math.pow(1024L, 2L)), | ||
| GiB ((long) Math.pow(1024L, 3L)), | ||
| TiB ((long) Math.pow(1024L, 4L)), | ||
| PiB ((long) Math.pow(1024L, 5L)); | ||
|
|
||
| private ByteUnit(long multiplier) { | ||
| this.multiplier = multiplier; | ||
|
|
@@ -39,25 +39,19 @@ public long convert(long d, ByteUnit u) { | |
| return toBytes(d) / u.multiplier; | ||
|
Contributor
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. If you want to be really correct here, you could avoid overflows by playing with the multipliers instead of converting things to bytes first. I think what's bugging me is that the semantics of all these methods are a little weird. It seems like you're trying to cap the maximum amount to be represented to
Contributor
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. I saw your comment about using double - I don't think that's a great idea because doubles lose precision as you try to work with values at different orders of magniture. Regarding the last paragraph of my comment above, I don't think it's going to be an issue in practice; but the code here can be changed to at least avoid overflows where possible. I checked |
||
| } | ||
|
|
||
| public long toBytes(long d) { return x(d, multiplier); } | ||
| public long toBytes(long d) { | ||
| if (d == 0) { return 0; } | ||
| long over = MAX / d; | ||
|
Contributor
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. Doesn't seem worth it to have a private |
||
| if (d > over) return Long.MAX_VALUE; | ||
|
Contributor
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. Hmmm... I feel like it would be better to throw an exception instead of truncating. |
||
| if (d < -over) return Long.MIN_VALUE; | ||
|
Contributor
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. Negative byte counts sound a little weird, but well. Same comment as above, though. |
||
| return d * multiplier; | ||
| } | ||
| public long toKiB(long d) { return convert(d, KiB); } | ||
| public long toMiB(long d) { return convert(d, MiB); } | ||
| public long toGiB(long d) { return convert(d, GiB); } | ||
| public long toTiB(long d) { return convert(d, TiB); } | ||
| public long toPiB(long d) { return convert(d, PiB); } | ||
|
|
||
| long multiplier = 0; | ||
| private long multiplier = 0; | ||
| static final long MAX = Long.MAX_VALUE; | ||
|
Contributor
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. not used anywhere?
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. Wanted to still keep these in case they were used down the line. Would you recommend getting rid of them?
Contributor
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. If you want this to be available, then it should be public. But I'd avoid adding it until it's actually needed. |
||
|
|
||
| /** | ||
| * Scale d by m, checking for overflow. | ||
| * This has a short name to make above code more readable. | ||
| */ | ||
| static long x(long d, long m) { | ||
| if (d == 0) { return 0; } | ||
| long over = MAX / d; | ||
| if (d > over) return Long.MAX_VALUE; | ||
| if (d < -over) return Long.MIN_VALUE; | ||
| return d * m; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,7 +212,7 @@ private static long parseByteString(String str, ByteUnit unit) { | |
| Matcher m = Pattern.compile("([0-9]+)([a-z]+)?").matcher(lower); | ||
| Matcher fractionMatcher = Pattern.compile("([0-9]*\\.[0-9]*)([a-z]+)?").matcher(lower); | ||
|
|
||
| if(m.matches()) { | ||
| if (m.matches()) { | ||
|
Contributor
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. nit: |
||
| long val = Long.parseLong(m.group(1)); | ||
| String suffix = m.group(2); | ||
|
|
||
|
|
||
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.
This automatic translation may throw a NumberFormatException if someone tries to use the .mb parameter as "64k" (e.g. the correct new format). Is that a case we should be concerned with? There will be enough warnings and errors thrown for them to readily track down the problem and fix the erroneous config so this should be ok but want to confirm that.
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.
I think since you're adding the new config, it's fine to not allow the old config take the new style. If you really want to support that, you could try to parse the config using the new API in an exception handler.
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.
very small nit, but I would put the
Seq(on L510 to be consistent with the rest.