szetszwo commented on a change in pull request #205: HDDS-2386. Implement 
incremental ChunkBuffer.
URL: https://github.com/apache/hadoop-ozone/pull/205#discussion_r350884795
 
 

 ##########
 File path: 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/IncrementalChunkBuffer.java
 ##########
 @@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.hadoop.ozone.common;
+
+import com.google.common.base.Preconditions;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Function;
+
+/**
+ * Use a list of {@link ByteBuffer} to implement a single {@link ChunkBuffer}
+ * so that the buffer can be allocated incrementally.
+ */
+final class IncrementalChunkBuffer implements ChunkBuffer {
+  /** Limit, which cannot be changed. */
+  private final int limit;
+  /** Increment is the capacity of each {@link ByteBuffer} in the list. */
+  private final int increment;
+  /** Buffer list to be allocated incrementally. */
+  private final List<ByteBuffer> buffers = new ArrayList<>();
+  /** Is this a duplicated buffer? */
+  private final boolean isDuplicated;
+
+  IncrementalChunkBuffer(int limit, int increment, boolean isDuplicated) {
+    Preconditions.checkArgument(limit >= 0);
+    Preconditions.checkArgument(increment > 0);
+    this.limit = limit;
+    this.increment = increment;
+    this.isDuplicated = isDuplicated;
+  }
+
+  /** @return the capacity for the buffer at the given index. */
+  private int getBufferCapacityAtIndex(int i) {
+    if (limit == 0) {
+      return 0;
+    } else if (i < limit/increment) {
 
 Review comment:
   Sure

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to