smengcl commented on code in PR #7189: URL: https://github.com/apache/ozone/pull/7189#discussion_r1835273458
########## hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumCache.java: ########## @@ -0,0 +1,115 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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 org.apache.ratis.thirdparty.com.google.protobuf.ByteString; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +/** + * Cache previous checksums to avoid recomputing them. + * This is a stop-gap solution to reduce checksum calc overhead inside critical section + * without having to do a major refactoring/overhaul over protobuf and interfaces. + * This is only supposed to be used by BlockOutputStream, for now. + * <p> + * Each BlockOutputStream has its own Checksum instance. + * Each block chunk (4 MB default) is divided into 16 KB (default) each for checksum calculation. + * For CRC32/CRC32C, each checksum takes 4 bytes. Thus each block chunk has 4 MB / 16 KB * 4 B = 1 KB of checksum data. + */ +public class ChecksumCache { + public static final Logger LOG = LoggerFactory.getLogger(ChecksumCache.class); + + private final int bytesPerChecksum; + private final List<ByteString> checksums; + // Chunk length last time the checksum is computed + private int prevChunkLength; + // This only serves as a hint for array list initial allocation. The array list will still grow as needed. + private static final int BLOCK_CHUNK_SIZE = 4 * 1024 * 1024; // 4 MB Review Comment: Yes. Chunk size is 4 MB by default. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
