You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2020/12/03 02:48:08 UTC

[iotdb] branch cluster_add_snappy updated: do not resize when reading request size

This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch cluster_add_snappy
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/cluster_add_snappy by this push:
     new 7962ebc  do not resize when reading request size
7962ebc is described below

commit 7962ebcb3cf81b7edd829f92a13846b3d3473a61
Author: jt <jt...@163.com>
AuthorDate: Thu Dec 3 10:46:45 2020 +0800

    do not resize when reading request size
---
 .../src/main/java/org/apache/iotdb/rpc/AutoExpandingBuffer.java  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoExpandingBuffer.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoExpandingBuffer.java
index 4fe0963..35a74d8 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoExpandingBuffer.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoExpandingBuffer.java
@@ -19,6 +19,8 @@
 package org.apache.iotdb.rpc;
 
 import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Helper class that wraps a byte[] so that it can expand and be reused. Users
@@ -34,6 +36,8 @@ class AutoExpandingBuffer {
   private byte[] array;
   private int bufTooLargeCounter = MAX_BUFFER_OVERSIZE_TIME;
 
+  private static final Logger logger = LoggerFactory.getLogger(AutoExpandingBuffer.class);
+
   public AutoExpandingBuffer(int initialCapacity) {
     this.array = new byte[initialCapacity];
   }
@@ -47,9 +51,12 @@ class AutoExpandingBuffer {
       int newCapacity = Math.max(growCapacity, size);
       this.array = Arrays.copyOf(array, newCapacity);
       bufTooLargeCounter = MAX_BUFFER_OVERSIZE_TIME;
-    } else if (array.length * loadFactor > size && bufTooLargeCounter-- <= 0) {
+      logger.info("{} expand from {} to {}", this, currentCapacity, newCapacity);
+    } else if (size > 8 && currentCapacity * loadFactor > size && bufTooLargeCounter-- <= 0) {
+      // do not resize if it is reading the request size
       array = Arrays.copyOf(array, size);
       bufTooLargeCounter = MAX_BUFFER_OVERSIZE_TIME;
+      logger.info("{} shrink from {} to {}", this, currentCapacity, size);
     }
   }