You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "ArafatKhan2198 (via GitHub)" <gi...@apache.org> on 2023/06/05 07:15:58 UTC

[GitHub] [ozone] ArafatKhan2198 commented on a diff in pull request #4764: HDDS-8585. Recon - API for Number of open keys and amount of data mapped to such keys.

ArafatKhan2198 commented on code in PR #4764:
URL: https://github.com/apache/ozone/pull/4764#discussion_r1217629169


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java:
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.hadoop.ozone.recon.schema.tables.daos.GlobalStatsDao;
+import org.hadoop.ozone.recon.schema.tables.pojos.GlobalStats;
+import org.jooq.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import java.util.Map.Entry;
+
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.OPEN_KEY_TABLE;
+import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.OPEN_FILE_TABLE;
+import static org.jooq.impl.DSL.currentTimestamp;
+import static org.jooq.impl.DSL.select;
+import static org.jooq.impl.DSL.using;
+
+/**
+ * Class to iterate over the OM DB and store the total counts of volumes,
+ * buckets, keys, open keys, deleted keys, etc.
+ */
+public class OmTableInsightTask implements ReconOmTask {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OmTableInsightTask.class);
+
+  private GlobalStatsDao globalStatsDao;
+  private Configuration sqlConfiguration;
+  private ReconOMMetadataManager reconOMMetadataManager;
+
+  @Inject
+  public OmTableInsightTask(GlobalStatsDao globalStatsDao,
+                            Configuration sqlConfiguration,
+                            ReconOMMetadataManager reconOMMetadataManager) {
+    this.globalStatsDao = globalStatsDao;
+    this.sqlConfiguration = sqlConfiguration;
+    this.reconOMMetadataManager = reconOMMetadataManager;
+  }
+
+  /**
+   * Iterates the rows of each table in the OM snapshot DB and calculates the
+   * counts and sizes for table data.
+   *
+   * For tables that require data size calculation
+   * (as returned by getTablesToCalculateSize), both the number of
+   * records (count) and total data size of the records are calculated.
+   * For all other tables, only the count of records is calculated.
+   *
+   * @param omMetadataManager OM Metadata instance.
+   * @return Pair
+   */
+  @Override
+  public Pair<String, Boolean> reprocess(OMMetadataManager omMetadataManager) {
+    HashMap<String, Long> objectCountMap = initializeCountMap();
+    HashMap<String, Long> sizeCountMap = initializeSizeMap();
+
+    for (String tableName : getTaskTables()) {
+      Table table = omMetadataManager.getTable(tableName);
+      if (table == null) {
+        LOG.error("Table " + tableName + " not found in OM Metadata.");
+        return new ImmutablePair<>(getTaskName(), false);
+      }
+
+      try {
+        if (getTablesToCalculateSize().contains(tableName)) {
+          Pair<Long, Long> details = getTableSizeAndCount(table);
+          objectCountMap.put(getTableCountKeyFromTable(tableName),
+              details.getLeft());
+          sizeCountMap.put(getTableSizeKeyFromTable(tableName),
+              details.getRight());
+        } else {
+          long count = getCount(table.iterator());
+          objectCountMap.put(getTableCountKeyFromTable(tableName), count);
+        }
+      } catch (IOException ioEx) {
+        LOG.error("Unable to populate Table Count in Recon DB.", ioEx);
+        return new ImmutablePair<>(getTaskName(), false);
+      }
+    }
+
+    writeDataToDB(objectCountMap);
+    writeDataToDB(sizeCountMap);
+
+    LOG.info("Completed a 'reprocess' run of OmTableInsightTask.");
+    return new ImmutablePair<>(getTaskName(), true);
+  }
+
+  /**
+   *  Returns a pair with the total count of records (left) and total data size
+   *  (right) in the given table. Increments count for each record and adds the
+   *  dataSize if a record's value is an instance of OmKeyInfo. If the table is
+   *  null, returns (0,0).
+   *
+   * @param table The table from which to get the count and data size.
+   * @return A pair of Long values of count & data size
+   * @throws IOException If an I/O error occurs during the table iteration.
+   */
+  public Pair<Long, Long> getTableSizeAndCount(Table table) throws IOException {
+    long size = 0;
+    long count = 0;
+    if (table == null) {

Review Comment:
   I agree it's not uselful here, I forgot it is already checked!
   I have removed it! Thanks 



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org