sumitagrawl commented on code in PR #5037: URL: https://github.com/apache/ozone/pull/5037#discussion_r1446967862
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/DeletedDirectoriesInsightHandler.java: ########## @@ -0,0 +1,229 @@ +/* + * 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.recon.tasks; + +import org.apache.commons.lang3.tuple.Triple; +import org.apache.hadoop.hdds.client.ReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +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.recon.api.types.NSSummary; +import org.apache.hadoop.ozone.recon.spi.impl.ReconNamespaceSummaryManagerImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hadoop.hdds.client.ReplicationConfig.parse; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_DEFAULT; + +/** + * Manages records in the Deleted Directory Table, updating counts and sizes of + * pending Directory Deletions in the backend. + */ +public class DeletedDirectoriesInsightHandler implements OmTableHandler { + + private ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager; + private int replicationFactor; + private OzoneConfiguration conf; + + private static final Logger LOG = + LoggerFactory.getLogger(DeletedKeysInsightHandler.class); + + public DeletedDirectoriesInsightHandler( + ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager) { + this.conf = new OzoneConfiguration(); + this.replicationFactor = getReplicationFactor(); + this.reconNamespaceSummaryManager = reconNamespaceSummaryManager; + } + + /** + * Invoked by the process method to add information on those directories that + * have been backlogged in the backend for deletion. + */ + @Override + public void handlePutEvent(OMDBUpdateEvent<String, Object> event, + String tableName, + Collection<String> sizeRelatedTables, + HashMap<String, Long> objectCountMap, + HashMap<String, Long> unreplicatedSizeMap, + HashMap<String, Long> replicatedSizeMap) { + String countKey = getTableCountKeyFromTable(tableName); + String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName); + + if (event.getValue() != null) { + OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue(); + objectCountMap.computeIfPresent(countKey, (k, count) -> count + 1L); + + try { + // Attempt to fetch size for deleted directory + Long newDeletedDirectorySize = + fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); + + unreplicatedSizeMap.computeIfPresent(unReplicatedSizeKey, + (k, size) -> size + newDeletedDirectorySize); + replicatedSizeMap.computeIfPresent(unReplicatedSizeKey, Review Comment: size can be different based on key type as EC or Ratis, so can not have direct multiplication as of ratis. Further a directory can have file of different replication type, can not take decision based default config. ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java: ########## @@ -65,14 +65,29 @@ public class OmTableInsightTask implements ReconOmTask { private GlobalStatsDao globalStatsDao; private Configuration sqlConfiguration; private ReconOMMetadataManager reconOMMetadataManager; + private ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager; + private Table<Long, NSSummary> nsSummaryTable; + private Map<String, OmTableHandler> tableHandlers; @Inject public OmTableInsightTask(GlobalStatsDao globalStatsDao, - Configuration sqlConfiguration, - ReconOMMetadataManager reconOMMetadataManager) { + Configuration sqlConfiguration, + ReconOMMetadataManager reconOMMetadataManager, + ReconNamespaceSummaryManagerImpl + reconNamespaceSummaryManager) { this.globalStatsDao = globalStatsDao; this.sqlConfiguration = sqlConfiguration; this.reconOMMetadataManager = reconOMMetadataManager; + this.reconNamespaceSummaryManager = reconNamespaceSummaryManager; + this.nsSummaryTable = reconNamespaceSummaryManager.getNSSummaryTable(); + + // Initialize table handlers + tableHandlers = new HashMap<>(); + tableHandlers.put(OPEN_KEY_TABLE, new OpenKeysInsightHandler()); Review Comment: getTablesToCalculateSize() can be removed and use tableHandlers only to avoid mismatch while iterate taskTable and using tableHandler to get data. ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/DeletedDirectoriesInsightHandler.java: ########## @@ -0,0 +1,229 @@ +/* + * 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.recon.tasks; + +import org.apache.commons.lang3.tuple.Triple; +import org.apache.hadoop.hdds.client.ReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +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.recon.api.types.NSSummary; +import org.apache.hadoop.ozone.recon.spi.impl.ReconNamespaceSummaryManagerImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hadoop.hdds.client.ReplicationConfig.parse; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_DEFAULT; + +/** + * Manages records in the Deleted Directory Table, updating counts and sizes of + * pending Directory Deletions in the backend. + */ +public class DeletedDirectoriesInsightHandler implements OmTableHandler { + + private ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager; + private int replicationFactor; + private OzoneConfiguration conf; + + private static final Logger LOG = + LoggerFactory.getLogger(DeletedKeysInsightHandler.class); + + public DeletedDirectoriesInsightHandler( + ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager) { + this.conf = new OzoneConfiguration(); + this.replicationFactor = getReplicationFactor(); + this.reconNamespaceSummaryManager = reconNamespaceSummaryManager; + } + + /** + * Invoked by the process method to add information on those directories that + * have been backlogged in the backend for deletion. + */ + @Override + public void handlePutEvent(OMDBUpdateEvent<String, Object> event, + String tableName, + Collection<String> sizeRelatedTables, + HashMap<String, Long> objectCountMap, + HashMap<String, Long> unreplicatedSizeMap, + HashMap<String, Long> replicatedSizeMap) { + String countKey = getTableCountKeyFromTable(tableName); Review Comment: There are 2 problem which will not give correct result: 1. duplicate counting of file size if files are present in sub-directory 2. size will not get dyanmically updated if some files of directory is deleted -- 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]
