hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] swagle commented on a change in pull request #1146: HDDS-1366. Add ability in Recon to track the number of small files in an Ozone Cluster
Date Mon, 05 Aug 2019 20:59:20 GMT
swagle commented on a change in pull request #1146: HDDS-1366. Add ability in Recon to track
the number of small files in an Ozone Cluster
URL: https://github.com/apache/hadoop/pull/1146#discussion_r310789626
 
 

 ##########
 File path: hadoop-ozone/ozone-recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/FileSizeCountTask.java
 ##########
 @@ -0,0 +1,254 @@
+/**
+ * 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.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.utils.db.Table;
+import org.apache.hadoop.utils.db.TableIterator;
+import org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao;
+import org.hadoop.ozone.recon.schema.tables.pojos.FileCountBySize;
+import org.jooq.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Class to iterate over the OM DB and store the counts of existing/new
+ * files binned into ranges (1KB, 10Kb..,10MB,..1PB) to the Recon
+ * fileSize DB.
+ */
+public class FileSizeCountTask extends ReconDBUpdateTask {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(FileSizeCountTask.class);
+
+  private int maxBinSize;
+  private long maxFileSizeUpperBound = 1125899906842624L; // 1 PB
+  private long[] upperBoundCount = new long[maxBinSize];
+  private long ONE_KB = 1024L;
+  private Collection<String> tables = new ArrayList<>();
+  private FileCountBySizeDao fileCountBySizeDao;
+
+  @Inject
+  public FileSizeCountTask(OMMetadataManager omMetadataManager,
+      Configuration sqlConfiguration) {
+    super("FileSizeCountTask");
+    try {
+      tables.add(omMetadataManager.getKeyTable().getName());
+      fileCountBySizeDao = new FileCountBySizeDao(sqlConfiguration);
+    } catch (Exception e) {
+      LOG.error("Unable to fetch Key Table updates ", e);
+    }
+  }
+
+  protected long getOneKB() {
+    return ONE_KB;
+  }
+
+  protected long getMaxFileSizeUpperBound() {
+    return maxFileSizeUpperBound;
+  }
+
+  protected int getMaxBinSize() {
+    return maxBinSize;
+  }
+
+  /**
+   * Read the Keys from OM snapshot DB and calculate the upper bound of
+   * File Size it belongs to.
+   *
+   * @param omMetadataManager OM Metadata instance.
+   * @return Pair
+   */
+  @Override
+  public Pair<String, Boolean> reprocess(OMMetadataManager omMetadataManager) {
+    LOG.info("Starting a 'reprocess' run of FileSizeCountTask.");
+
+    fetchUpperBoundCount("reprocess");
+
+    Table<String, OmKeyInfo> omKeyInfoTable = omMetadataManager.getKeyTable();
+    try (TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>>
+        keyIter = omKeyInfoTable.iterator()) {
+      while (keyIter.hasNext()) {
+        Table.KeyValue<String, OmKeyInfo> kv = keyIter.next();
+        countFileSize(kv.getValue());
+      }
+    } catch (IOException ioEx) {
+      LOG.error("Unable to populate File Size Count in Recon DB. ", ioEx);
+      return new ImmutablePair<>(getTaskName(), false);
+    } finally {
+      populateFileCountBySizeDB();
+    }
+
+    LOG.info("Completed a 'reprocess' run of FileSizeCountTask.");
+    return new ImmutablePair<>(getTaskName(), true);
+  }
+
+  void setMaxBinSize() {
+    maxBinSize = (int)(long) (Math.log(getMaxFileSizeUpperBound())
+        /Math.log(2)) - 10;
+    maxBinSize += 2;  // extra bin to add files > 1PB.
+  }
+
+  void fetchUpperBoundCount(String type) {
+    setMaxBinSize();
+    if (type.equals("process")) {
+      //update array with file size count from DB
+      List<FileCountBySize> resultSet = fileCountBySizeDao.findAll();
+      int index = 0;
+      if (resultSet != null) {
+        for (FileCountBySize row : resultSet) {
+          upperBoundCount[index] = row.getCount();
+          index++;
+        }
+      }
+    } else {
+      upperBoundCount = new long[getMaxBinSize()];    //initialize array
+    }
+  }
+
+  @Override
+  protected Collection<String> getTaskTables() {
+    return tables;
+  }
+
+  /**
+   * Read the Keys from update events and update the count of files
+   * pertaining to a certain upper bound.
+   *
+   * @param events Update events - PUT/DELETE.
+   * @return Pair
+   */
+  @Override
+  Pair<String, Boolean> process(OMUpdateEventBatch events) {
+    LOG.info("Starting a 'process' run of FileSizeCountTask.");
+    Iterator<OMDBUpdateEvent> eventIterator = events.getIterator();
+
+    fetchUpperBoundCount("process");
 
 Review comment:
   This code is very hard to follow, it can be simplified a bit.
   1. Since Math.log2 is hardcoded and not something configurable, meaning take log to base
10 or base 2, the total number of bins is fixed anyways, right?
   2. Process and reprocess can initialize the array instead of fetchUpperBoundCount, IMO

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


Mime
View raw message