szetszwo commented on a change in pull request #205: HDDS-2386. Implement incremental ChunkBuffer. URL: https://github.com/apache/hadoop-ozone/pull/205#discussion_r347177313
########## File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/IncrementalChunkBuffer.java ########## @@ -0,0 +1,217 @@ +/* + * 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<>(); + + IncrementalChunkBuffer(int limit, int increment) { + Preconditions.checkArgument(limit >= 0); + Preconditions.checkArgument(increment > 0); Review comment: It will be harder to use the class if we do not allow increment > limit. For example, bytePerChecksum is 1MB but actually data size is 1KB. Then, we cannot allocate a ChunkBuffer with limit=1KB and increment=1MB. ---------------------------------------------------------------- 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]
