ChenSammi commented on code in PR #8651: URL: https://github.com/apache/ozone/pull/8651#discussion_r2203963843
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/MultipartInfoInsightHandler.java: ########## @@ -0,0 +1,161 @@ +/* + * 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.recon.tasks; + +import java.util.Map; +import org.apache.commons.lang3.tuple.Triple; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Manages records in the MultipartInfo Table, updating counts and sizes of + * multipart upload keys in the backend. + */ +public class MultipartInfoInsightHandler implements OmTableHandler { + + private static final Logger LOG = + LoggerFactory.getLogger(MultipartInfoInsightHandler.class); + + /** + * Invoked by the process method to add information on those keys that have + * been initiated for multipart upload in the backend. + */ + @Override + public void handlePutEvent(OMDBUpdateEvent<String, Object> event, String tableName, Map<String, Long> objectCountMap, + Map<String, Long> unReplicatedSizeMap, Map<String, Long> replicatedSizeMap) { + + if (event.getValue() != null) { + OmMultipartKeyInfo multipartKeyInfo = (OmMultipartKeyInfo) event.getValue(); + objectCountMap.computeIfPresent(getTableCountKeyFromTable(tableName), + (k, count) -> count + 1L); + + for (PartKeyInfo partKeyInfo : multipartKeyInfo.getPartKeyInfoMap()) { + OmKeyInfo omKeyInfo = OmKeyInfo.getFromProtobuf(partKeyInfo.getPartKeyInfo()); + unReplicatedSizeMap.computeIfPresent(getUnReplicatedSizeKeyFromTable(tableName), + (k, size) -> size + omKeyInfo.getDataSize()); + replicatedSizeMap.computeIfPresent(getReplicatedSizeKeyFromTable(tableName), + (k, size) -> size + omKeyInfo.getReplicatedSize()); + } + } else { + LOG.warn("Put event does not have the Multipart Key Info for {}.", event.getKey()); + } + } + + /** + * Invoked by the process method to delete information on those multipart uploads that + * have been completed or aborted in the backend. + */ + @Override + public void handleDeleteEvent(OMDBUpdateEvent<String, Object> event, String tableName, + Map<String, Long> objectCountMap, Map<String, Long> unReplicatedSizeMap, Map<String, Long> replicatedSizeMap) { + + if (event.getValue() != null) { + OmMultipartKeyInfo multipartKeyInfo = (OmMultipartKeyInfo) event.getValue(); + objectCountMap.computeIfPresent(getTableCountKeyFromTable(tableName), + (k, count) -> count > 0 ? count - 1L : 0L); + + for (PartKeyInfo partKeyInfo : multipartKeyInfo.getPartKeyInfoMap()) { + OmKeyInfo omKeyInfo = OmKeyInfo.getFromProtobuf(partKeyInfo.getPartKeyInfo()); + unReplicatedSizeMap.computeIfPresent(getUnReplicatedSizeKeyFromTable(tableName), + (k, size) -> size > omKeyInfo.getDataSize() ? + size - omKeyInfo.getDataSize() : 0L); Review Comment: If event will not be processed multiple times, then theoretically size will not go negative. Could you log a message if it's negative? -- 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]
