You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/10/09 04:47:35 UTC
[GitHub] [flink] KarmaGYZ commented on a change in pull request #9760:
[FLINK-13982][runtime] Implement memory calculation logics
KarmaGYZ commented on a change in pull request #9760: [FLINK-13982][runtime] Implement memory calculation logics
URL: https://github.com/apache/flink/pull/9760#discussion_r332811245
##########
File path: flink-core/src/main/java/org/apache/flink/configuration/MemorySize.java
##########
@@ -115,6 +116,28 @@ public String toString() {
return bytes + " bytes";
}
+ // ------------------------------------------------------------------------
+ // Calculations
+ // ------------------------------------------------------------------------
+
+ public MemorySize add(MemorySize that) {
+ return new MemorySize(Math.addExact(this.bytes, that.bytes));
+ }
+
+ public MemorySize subtract(MemorySize that) {
+ return new MemorySize(Math.subtractExact(this.bytes, that.bytes));
+ }
+
+ public MemorySize multiply(double multiplier) {
+ checkArgument(multiplier >= 0, "multiplier must be >= 0");
+
+ BigDecimal product = BigDecimal.valueOf(this.bytes).multiply(BigDecimal.valueOf(multiplier));
+ if (product.longValue() > Long.MAX_VALUE) {
+ throw new ArithmeticException("long overflow");
+ }
Review comment:
`BigDecimal::longValue` guarantee that its return value less than `Long.MAX_VALUE` and if the resulting is too big to fit in a `long`, only the low-order 64 bits are returned. So this check is useless, `BigDecimal::compareTo` could be a valid way to compare.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services