Repository: asterixdb Updated Branches: refs/heads/master e2cf9c271 -> 2b10c1c95
[NO ISSUE][RT] Remove Hard Memory Limit in ByteArrayAccessibleOutputStream - user model changes: no - storage format changes: no - interface changes: no Details: - Remove the hardcoded 64MB memory limit from ByteArrayAccessibleOutputStream as the limit shouldn't be controlled by this structure but rather by operators using it. Change-Id: Ia88861c44802e64dbfceb5e8efc75d28bd54b501 Reviewed-on: https://asterix-gerrit.ics.uci.edu/2073 Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/2b10c1c9 Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/2b10c1c9 Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/2b10c1c9 Branch: refs/heads/master Commit: 2b10c1c95ee1bcd4c529faed93b5ba05310cae3c Parents: e2cf9c2 Author: Murtadha Hubail <mhub...@apache.org> Authored: Sat Oct 14 23:07:45 2017 +0300 Committer: Murtadha Hubail <mhub...@apache.org> Committed: Sat Oct 14 19:17:36 2017 -0700 ---------------------------------------------------------------------- .../util/ByteArrayAccessibleOutputStream.java | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2b10c1c9/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java index bf0e1dd..1a806cd 100644 --- a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java +++ b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java @@ -23,8 +23,7 @@ import java.util.Arrays; public class ByteArrayAccessibleOutputStream extends ByteArrayOutputStream { - private static final int MAX_SIZE = 1024 * 1024 * 32; - private static final double BUFFER_INCREMENT_FACTOR = 1.5; + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE; public ByteArrayAccessibleOutputStream() { super(); @@ -97,22 +96,24 @@ public class ByteArrayAccessibleOutputStream extends ByteArrayOutputStream { private void grow(int minCapacity) { // overflow-conscious code int oldCapacity = buf.length; - if (oldCapacity == MAX_SIZE) { - throw new IllegalArgumentException("Buffer is too large..."); - } - int newCapacity = Math.min((int) (oldCapacity * BUFFER_INCREMENT_FACTOR), MAX_SIZE); + // increase by a factor of 1.5 + int newCapacity = oldCapacity + (oldCapacity >> 1); if (newCapacity - minCapacity < 0) { newCapacity = minCapacity; } - if (newCapacity < 0) { - if (minCapacity < 0) { - throw new OutOfMemoryError(); - } - newCapacity = Integer.MAX_VALUE; + if (newCapacity - MAX_ARRAY_SIZE > 0) { + newCapacity = hugeCapacity(minCapacity); } buf = Arrays.copyOf(buf, newCapacity); } + private static int hugeCapacity(int minCapacity) { + if (minCapacity < 0) { // overflow + throw new RuntimeException("Memory allocation limit (" + MAX_ARRAY_SIZE + " bytes) exceeded"); + } + return (minCapacity > MAX_ARRAY_SIZE) ? Integer.MAX_VALUE : MAX_ARRAY_SIZE; + } + /** * Return the current length of this stream (not capacity). */